BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10

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

 

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Hi @Q1983    Do you mean , should a column be all missings, you want to replace with zero?

Q1983
Lapis Lazuli | Level 10

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.

novinosrin
Tourmaline | Level 20

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;

 

Patrick
Opal | Level 21

@Q1983 

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;

Capture.JPG

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
  • 4 replies
  • 465 views
  • 0 likes
  • 3 in conversation