the following code will read multi observations per line.
data body_fat;
input Gender $ PercentFat @@;
datalines;
m 13.3 f 22
m 22 f 23.2
m 16 m 12
;
run;
how do i populate the data with only M patients?
Use a subsetting if:
data body_fat;
input Gender $ PercentFat @@;
if gender = 'm';
datalines;
m 13.3 f 22
m 22 f 23.2
m 16 m 12
;
run;
Something like:
if gender="M" then output;
Use a subsetting if:
data body_fat;
input Gender $ PercentFat @@;
if gender = 'm';
datalines;
m 13.3 f 22
m 22 f 23.2
m 16 m 12
;
run;
Hi,
This looks a bit like homework. What have you tried so far? Share any code you have tried and show the log with any error messages.
If you haven't tried anything yet then try looking at the if statement documentation, which includes examples:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000202239.htm
then you can post back your findings.
Regards,
Amir.
Hi,
When I tried your code to split the genders, I had no apparent issues.
The M data set had 4 observations and the F data set had 2 observations.
NOTE: The data set WORK.MBODY_FAT has 4 observations and 2 variables. NOTE: The data set WORK.FBODY_FAT has 2 observations and 2 variables.
What do you get or what were you expecting?
Regards,
Amir.
@Dennis_K wrote:
data mbody_fat fbody_fat;
@input Gender $ PercentFat @@;
IF Gender='m' then
output mbody_fat;
else IF Gender='f' then
output fbody_fat;
datalines;
m 13.3 f 22
m 22 f 23.2
m 16 m 12
;
run;
Somehow the ELSE statement does not work
It does work, see this log:
27 data mbody_fat fbody_fat; 28 29 input Gender $ PercentFat @@; 30 31 IF Gender='m' then 32 output mbody_fat; 33 else IF Gender='f' then 34 output fbody_fat; 35 36 datalines; NOTE: SAS went to a new line when INPUT statement reached past the end of a line. NOTE: The data set WORK.MBODY_FAT has 4 observations and 2 variables. NOTE: The data set WORK.FBODY_FAT has 2 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.00 seconds 40 ; 41 run;
I just copy/pasted your code and ran it.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.