Hi guys,
I am new to SAS and I am a bit confused on how to use the class statement for two datasets. I thought I would not need to merge them with a class but I am not sure. Please see the code I have written below which is missing the second dataset because I am not sure where it fits in:
/* My question
Using the SAS datasets demogdemo and visitdemo and PROC MEANS with the CLASS statement, compute the mean, median, 25th percentile,
75th percentile, and the number of non-missing values for the variables CD4, Weight, and Age for each value of civil status
including missing. Report the statistics to three decimal places. In the same PROC MEANS, create a summary dataset with the
OUTPUT statement containing the median and mean of CD4, Weight, and Age. Using _TYPE_, print only the overall (i.e. all civil
status categories combined) mean and median from this summary dataset. */
/*My starter solution*/
title "Using a CLASS Statement with PROC MEANS";
proc means data=lb.visitdemo n mean median Q1 Q3 maxdec=3; *where do I put demogdemo? Do I need to merge it in with visit demo in a different datastep first?;
class civilstatus;
var CD4 Weight Age ;
output out = newdataset;
median = md_CD4 md_Weight md_Age;
mean = m_CD4 m_Weight m_Age;
run;
proc
If you have variables in both data sets that you want to use at the same time within PROC MEANS you have to merge the files.
@cheenaChuks wrote:
Which variables are coming from which dataset? CD4 is from demog data while apptdate and all the other variables are from visit data. Patient id is in both of them.
Do they both actually have the variable PATIENT_ID? yes. Are they sorted? yes
Do they both have one observation per PATIENT_ID? yes Or does only one have multiple observations per PATIENT_ID? no
You have left out a lot of key information but I think the answer is you cannot use one proc step to operate on multiple input datasets.
data for_analysis;
length insdname $41 ds $32 ;
set demog1 demog2 indsname=indsname;
ds=scan(indsname,-1,'.');
run;
proc means data=for_analysis;
class ds;
....
run;
What information is missing out please? I have modified my code but I had to do a merge by" first. I don't think this is what my professor wanted but I am not sure there are other ways. Is there a way to use the proc means without the first data steo I included? Could you take a look at the edited code?
data myMerger (keep = patient_id CD4 Weight Age civilstatus); /* Keeping required variables for future proc means*/
merge lb.visitdemo lb.demogdemo;
by patient_id;
title "Using a CLASS Statement with PROC MEANS";
proc means data=myMerger n mean median Q1 Q3 maxdec=3;
class civilstatus;
var CD4 Weight Age ;
output out = newdataset
median = md_CD4 md_Weight md_Age
mean = m_CD4 m_Weight m_Age;
run;
proc print data = newdataset;
run;
?
We have no idea if that is right since we know nothing about the two datasets. Which variables are coming from which dataset?
Do they both actually have the variable PATIENT_ID? Are they sorted?
Do they both have one observation per PATIENT_ID? Or does only one have multiple observations per PATIENT_ID? Or do both ?
Which variables are coming from which dataset? CD4 is from demog data while apptdate and all the other variables are from visit data. Patient id is in both of them.
Do they both actually have the variable PATIENT_ID? yes. Are they sorted? yes
Do they both have one observation per PATIENT_ID? yes Or does only one have multiple observations per PATIENT_ID? no
If you have variables in both data sets that you want to use at the same time within PROC MEANS you have to merge the files.
@cheenaChuks wrote:
Which variables are coming from which dataset? CD4 is from demog data while apptdate and all the other variables are from visit data. Patient id is in both of them.
Do they both actually have the variable PATIENT_ID? yes. Are they sorted? yes
Do they both have one observation per PATIENT_ID? yes Or does only one have multiple observations per PATIENT_ID? no
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.