BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dennis_K
Obsidian | Level 7

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?

 

1 ACCEPTED SOLUTION
6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Something like:

if gender="M" then output;
Amir
PROC Star

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.

Dennis_K
Obsidian | Level 7
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
Amir
PROC Star

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.

Kurt_Bremser
Super User

@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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 671 views
  • 0 likes
  • 4 in conversation