data temp;
infile DATALINES dsd missover;
input a $ b $ c $ d $;
CARDS;
, 2, 3, 4
, 3, , 5
, 3
;
run;
This code will list a with no records. Actually I am using a proc sql however using the above discussion. In my proc sql, the A column does not show up if there were no records. My question is, in the event of no records how can I still show the column and assign a 0 to show that there were no records for (in this case column A) The reason for this need is that I need to do a proc transpose and need to show all columns even if there are no records for a column
Hi @Q1983 Do you mean , should a column be all missings, you want to replace with zero?
For example in this datastep column A would show up with no records. So for A I still want to show the column A and assign 0 in the rows.
Hi @Q1983 Well FWIW, I'm offering an approach based on my understanding of your objective. Of course you are better off waiting for somebody like Tom to chime in as they can provide more guided and pointed approaches/solutions
data temp;
infile DATALINES dsd missover;
input a $ b $ c $ d $;
CARDS;
, 2, 3, 4
, 3, , 5
, 3
;
/*Get a subset of columns that has all missing values*/
ods output nlevels =nlevels(where=(nlevels=nmisslevels));
proc freq data=temp nlevels ;
tables _all_ /noprint ;
run;
/*Assign zero for the identified columns in the previous step*/
data _null_;
set nlevels(keep=tablevar) end=z;
if _n_=1 then call execute('data want;set temp;');
call execute(tablevar||'='||'"0";');
if z then call execute('run;');
run;
Before trying to provide a solution we need to understand the problem. What you describe doesn't add up for me because Proc Transpose will treat a missing like any other value and won't drop observations even if all variables are missing. Using your sample below code illustrates this behavior. So... What's the problem?
data temp;
infile DATALINES dsd missover;
input a $ b $ c $ d $;
CARDS;
, 2, 3, 4
, 3, , 5
, 3
;
run;
proc transpose data=temp out=want prefix=wantvar_;
var a b;
run;
proc print data=want;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.