Hello, I am looking for some advice since I have had problems creating two data sets composed of females and males from a permanent data set in SAShelp.
I used the if statement, but the data set that was created from there was empty.
Could you help me see what the problem is?
Thanks in advance
I added the code and log data.
libname assignew " /folders/myfolders/study4";
data assignew;
set SASHELP.HEART;
run;
proc print data=assignew (obs=10);
run;
proc contents data=assignew varnum;
run;
data fem;
set SASHELP.HEART;
if sex = 'f' then output Fem;
run;
data male;
set SASHELP.HEART;
if sex = 'm' then output male;
run;
proc freq data=FEM ;
tables Smoking_Status;
run;
LOG
Hi @xoxozav_1,
If you look at the SASHELP.HEART data set, you see that the Sex variable is coded as Female and Male, not m and f. So if you change your code to
data fem;
set SASHELP.HEART;
if sex = 'Female' then output Fem;
run;
then it should create a fem data set that includes only the Female observations from SASHELP.HEART.
You might also consider using a WHERE clause instead:
data fem2;
set SASHELP.HEART(where=(sex = 'Female'));
run;
If you look at the log for both approaches, you see that the first approach reads in all 5209 observations from SASHELP.HEART, whereas the second approach with the WHERE clause reads in only the 2873 Female observations of interest. This can help with efficiency.
Does that solve your problem?
Thanks,
-Brian
Hi @xoxozav_1,
If you look at the SASHELP.HEART data set, you see that the Sex variable is coded as Female and Male, not m and f. So if you change your code to
data fem;
set SASHELP.HEART;
if sex = 'Female' then output Fem;
run;
then it should create a fem data set that includes only the Female observations from SASHELP.HEART.
You might also consider using a WHERE clause instead:
data fem2;
set SASHELP.HEART(where=(sex = 'Female'));
run;
If you look at the log for both approaches, you see that the first approach reads in all 5209 observations from SASHELP.HEART, whereas the second approach with the WHERE clause reads in only the 2873 Female observations of interest. This can help with efficiency.
Does that solve your problem?
Thanks,
-Brian
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.