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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.