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  

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1006 views
  • 2 likes
  • 2 in conversation