Python Forum
how to code in Python "where" clause of SAS
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to code in Python "where" clause of SAS
#1
I am newcomer in Python, I am expert in SAS, I have heard that Python is much more ... better than SAS.
I am now trying to create in Python product doing the same as multi-module product in SAS, performing complex iterative process involving matrix operations with huge matrices. The first step is to read data from SAS data set, with "where" clause.
In SAS this step could be written very shortly and in easy-to-interpret way:

data aaa; set &dsin_ext(where=(&where));
if (&year_min<=year<=&year_max) and
(&age_min <=age <=&age_max );
zvar=&&&mapin&ltype;
run;

I have constructed Python code for this, however it looks so cumbersome. Could someone draft the same in short and nice way.
Thanks.
Reply
#2
(Mar-26-2019, 01:47 PM)FelixS Wrote: I have constructed Python code for this, however it looks so cumbersome.
Post your python code in python tags
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# “%cd” is one of magic command.
%cd C:\D\WinSAS\HF\HF13A\sb
adsl = pd.read_sas('hf_f014.sas7bdat', format='sas7bdat')
adsl
# the next is testing filtering
adsl1=adsl[(adsl['sex']==b'1') & (adsl['area']==b'2') ]
adsl1[(adsl1['age'] >=25 )&(adsl1['age']<=64)  & (adsl1['year'] >=1972 )&(adsl1['year']<=2002) ]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use the LIKE clause in Python Columbo 9 1,620 Oct-09-2022, 10:22 PM
Last Post: Larz60+
  SQL Query is not executing WHERE clause hammer 7 2,328 Nov-15-2021, 01:44 PM
Last Post: hammer
  How does this if clause work? Pedroski55 3 2,272 Jun-10-2021, 06:31 AM
Last Post: Gribouillis
  can i raise an exception in a try clause? Skaperen 14 5,724 Dec-19-2019, 12:29 AM
Last Post: Skaperen
  pass captured value from input() to where clause metro17 5 3,267 Sep-09-2019, 05:24 AM
Last Post: metro17
  finally clause Skaperen 6 3,874 Jun-02-2019, 09:02 PM
Last Post: snippsat
  if clause fails DeadCthulhuWaitsDreaming 10 4,752 Apr-07-2019, 09:19 PM
Last Post: DeadCthulhuWaitsDreaming
  break Statements and else Clause on Loops Phytonnewbie 2 2,789 Mar-02-2018, 09:50 AM
Last Post: buran
  My else clause doesn't work (general help) NMW 10 7,912 Jul-17-2017, 01:07 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020