BookmarkSubscribeRSS Feed
MisterJenn
Fluorite | Level 6

I want to create an indicator variable for 'male' sex. However, I do not have gender or sex as variables in my data set. I have two different data sets (data set for males) and (data set for females). I am trying to combine the two data sets which is why I need help with this. 

 

libname hw6 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Desktop\Assignment 6';
data hw6.sex_f_temp(rename=(subj_id_char=number) drop=subj_id);
set hw6.sex_f;
subj_id_char = input(subj_id, 4.);
run;
proc sort data=hw6.sex_f_temp; by number; 
proc sort data=hw6.sex_m; by number;
data pbc;
set hw6.sex_f_temp hw6.sex_m; 
by number;
logALBUMIN=log(ALBUMIN);
if male = 1 then sex = 1;
if female = 1 then sex=0;
run;
3 REPLIES 3
PaigeMiller
Diamond | Level 26

How about this:

 

data pbc;
set hw6.sex_f_temp(in=f) hw6.sex_m(in=m); 
by number;
if f then sex='F';
else if m then sex='M';
run;
--
Paige Miller
ballardw
Super User

If the idea is to add an indicator based on the source data set use the data set option IN. In creates a 1/0 temporary variable that indicates the current record comes from a given set (1) or not (0). So you can perform any conditional calculations you need to set such things. Below is very generic example

 

data want;
    set dataset1 (in=inset1)
         dataset2 (in= inset2)
   ;
   if inset1 then indicator = 1;
   else if inset2 then indicator=0;
  /* or what ever variable /values you want to set*/
run;
tarheel13
Rhodochrosite | Level 12

unrelated but when getting the log of albumin you should probably only do that when albumin is > 0.

SAS Innovate 2025: Register Now

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 620 views
  • 2 likes
  • 4 in conversation