10-24-2015 05:51 PM
I have situation where I have 3 treatment variables. some times there might note be any data pertaining trt3 but I need to get the variable trt3 in the dataset. How can I achieve this?
It may be trt2 or trt1 also missing, so I need to get automatically the missing treatment columns dynamically!
10-24-2015 06:19 PM
Hello, you can create an empty dataset with the 3 variables and set with your actual data so all your vars are available even if one is missing as in the example below:
data in1; infile datalines dlm='09'x; input trt1:$2. trt2 $2. trt3 $2.;; datalines; 2 12 15 ; run; data in1; set in1(obs=0);RUN; proc print; data in2;infile datalines dlm='09'x; input trt1:$2. ; datalines; 2 ;RUN; data final; set in1 in2; run; proc print; run;
10-25-2015 10:08 AM - edited 10-25-2015 10:10 AM
If you're reading a flat file, as Tom mentioned in his post, the TRUNCOVER option can help. However, if you are bringing in a couple of SAS datasets and if you need to have a set of variables in your output dataset, then you're better off in creating an empty dataset and using it as a template along with the other datasets that you are reading in which may or may not have your required variables, so you know for sure that you will have those variables coming from the template in your output.
Hope this makes sense.
10-24-2015 09:43 PM
I think perhaps you meant something a little different than what you wrote. For if you have three variables then it doesn't matter if the values are missing the variables are there. But if you have one varaible with potentially three values then the fact that one of the potential values does not appear might be a concern.
That is what the COMPLETETYPES and/or CLASSDATA options on PROC MEANS is designed to deal with.
10-24-2015 11:14 PM - edited 10-24-2015 11:17 PM
I come across this situation while generating the counts by treatment, so here is the approach that i follow
libname sampsio list; /*create a format for the missing treatment as well, here as per data treatment 5 is missing*/ proc format; value drug 1='trt1' 2='trt2' 3='trt3' 4='trt4' 5='trt5'; run; /*use the completetypes along with preloadfmt and format to apply the format to treatment so that while */ /*calculating frequency counts even for missing treatment count will be created*/ proc summary data=sampsio.drug n completetypes nway; class drug / preloadfmt; var chang_bp; format drug drug.; output out=freq n=count; run; /*finally transpose the data to see the missing treatment variable, here */ /*from the data treatment 5 was missing but it appears in the final dataset*/ proc transpose data=freq out=trt; id drug; var count; run;
10-25-2015 08:05 AM
I think what SASLICK is saying is that trt1 or trt2 or trt3 is blank in some records. Such as.
id trt1 trt2 trt3
1 45 22 21c
2 33 33
4 7 9
and wants to input the record and set trt1 trt2 trt3 to missing..
10-25-2015 10:03 AM - edited 10-25-2015 10:04 AM
That is what the TRUNCOVER option on the INFILE statement is for.
data want ; infile cards truncover ; input id trt1-trt3 ; cards; 1 45 22 21 2 33 33 3 4 7 9 ;;;;