BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kalai2008
Pyrite | Level 9

Hello,

 

I have 5 columns with values as 0 or 1.

Id Col1 Col2 Col3 Col4 Col5
1    1     0       0       1       0

2    1     0       0       1       0

3    0     1       0       1       0

4    1     0       0       1       0

5    0     0       0       0       1

I am running a big program every week,the issue is for some week, one of the column have no data, hence that particular column itself is missing. For my report, I need that column,  so  would like to add a dummy column( missing column lets say col5) and assign values as 0. I tried Proc sql with case statement at the end of the final dataset which is not working.

 

Thanks for checking.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

The harder part is setting to 0, adding the column is relatively trivial. Make a table with the structure you want and append it to that with 0 obs from the master table. 

 

If you can have missing in you data this makes this a bit more complex, but if you don't, you can set any missing to 0 and be done.

 

proc sql;
   create table table_format 
       (ID char(8),
        Col1 num,
        Col2 num,
        Col3 num,
        Col4 num,
        Col5 num);
quit;

proc sql;
   create table myData
       (ID char(8),
        Col1 num,
        Col2 num,
        Col3 num,
        Col5 num);
   insert into myData
   values ('1', 1, 0, 0, 1)
   values ('2', 1, 0, 1, 0);
quit;


data want;
set table_format(Obs=0) myData;
run;

View solution in original post

4 REPLIES 4
ballardw
Super User

Better would be to show an example of the input file with your problem and then what the desired output for that file would look like.

 

For instance, I am not sure when you say " one of the column have no data" whether that means the value of a variable is missing for all rows or data or only for a few.

What do you want if two variables are showing this behavior? or three?

 

 

Kalai2008
Pyrite | Level 9

Thanks ! You are right. This behavior can happen to 2 or more variables.

 

What I meant no data means, the value of the variable is missing for all rows  from the prior step. I can't able to show the data in detail.

Reeza
Super User

The harder part is setting to 0, adding the column is relatively trivial. Make a table with the structure you want and append it to that with 0 obs from the master table. 

 

If you can have missing in you data this makes this a bit more complex, but if you don't, you can set any missing to 0 and be done.

 

proc sql;
   create table table_format 
       (ID char(8),
        Col1 num,
        Col2 num,
        Col3 num,
        Col4 num,
        Col5 num);
quit;

proc sql;
   create table myData
       (ID char(8),
        Col1 num,
        Col2 num,
        Col3 num,
        Col5 num);
   insert into myData
   values ('1', 1, 0, 0, 1)
   values ('2', 1, 0, 1, 0);
quit;


data want;
set table_format(Obs=0) myData;
run;

Kalai2008
Pyrite | Level 9

Thank you.. It worked. Setting up 0 was easy for me.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 773 views
  • 0 likes
  • 3 in conversation