BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

 

Hello, 

 

I have columns in Excel which have blank values. After importing to SAS they all now have a dot as shown below in the "have "dataset. Now the requirement is to subtract all these variables from 4 as shown. After performing the calculation to my surprise i still have missing values instead of 4. Did i miss anything?

 

 

data have

PAL1 PAL2 PAL3 PAL4

  .           .     .         .

run;

 

 

data Want;

set have;

paL1_=4-pal1;

pal2_=4-pal2;

pal3_=4-Pal3;

pal4_=4-pal4;

 

run;

 

Thank you

 

1 REPLY 1
Kurt_Bremser
Super User

Simple calculations involving missing values will result in missing values; the log (Maxim 2) alerts you to that.

The sum() function will count missing values as zero, so you can use it here:

data have;
input pal1-pal4;
cards;
. . . .
;
run;

data want;
set have;
pal1_ = sum(4,-pal1);
pal2_ = sum(4,-pal2);
pal3_ = sum(4,-pal3);
pal4_ = sum(4,-pal4);
run;

proc print data=want noobs;
run;

Result:

pal1    pal2    pal3    pal4    pal1_    pal2_    pal3_    pal4_

  .       .       .       .       4        4        4        4  

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 639 views
  • 2 likes
  • 2 in conversation