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

Dear experts,

can you please help me understand the below code,

I am not getting what .b ,.c is doing in do loop here.

 

data want (rename=(acc_id=acct_id));

set have;

   array nomiss ttl;

   do i=1 to dim(nomiss);

            if nomiss{i} in (.b,.c) then nomiss{i}=0;

            if nomiss{i} in (.d) then nomiss{i}=999;

            if nomiss{i} in (.e) then nomiss{i}=9999996;

   end;

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

.A-.Z are special missing values. 

 

For example, if you're doing a survey and someone doesn't answer a question you may want to mark that as missing. But if the question uses skip logic - only some people are asked the question - you may want to identify that differently, so you may code missing because they didn't answer as .A and missing because not asked as .B and missing because of some other reason, .Z

 

Here's the documentation reference on Missing Values

https://documentation.sas.com/?docsetId=lrcon&docsetTarget=p175x77t7k6kggn1io94yedqagl3.htm&docsetVe...

 


@Trishjais wrote:

Dear experts,

can you please help me understand the below code,

I am not getting what .b ,.c is doing in do loop here.

 

data want (rename=(acc_id=acct_id));

set have;

   array nomiss ttl;

   do i=1 to dim(nomiss);

            if nomiss{i} in (.b,.c) then nomiss{i}=0;

            if nomiss{i} in (.d) then nomiss{i}=999;

            if nomiss{i} in (.e) then nomiss{i}=9999996;

   end;

run;

 


 

View solution in original post

8 REPLIES 8
ballardw
Super User

@Trishjais wrote:

Dear experts,

can you please help me understand the below code,

I am not getting what .b ,.c is doing in do loop here.

 

data want (rename=(acc_id=acct_id));

set have;

   array nomiss ttl;

   do i=1 to dim(nomiss);

            if nomiss{i} in (.b,.c) then nomiss{i}=0;

            if nomiss{i} in (.d) then nomiss{i}=999;

            if nomiss{i} in (.e) then nomiss{i}=9999996;

   end;

run;

 


SAS allows 27 "special missing" values in addition to the standard missing represented by default "." . These are .A through .Z (26 letters, case doesn't matter) and ._  Just like the missing value, the special missing values are not used in calculations.

 

So the code is comparing the specific missing values to assign numeric values for some reason. I really hope the reason is for export to a different data system / file or else calculations are likely going to be very screwy.

 

Another approach is outlined here: https://communities.sas.com/t5/SAS-Programming/Character-and-Numeric-in-Same-Field/m-p/686382  where a format is used to display the values but would maintain the missing values.

PaigeMiller
Diamond | Level 26

There are 28 different missing vlaues in SAS. You are probably familiar with the dot as  a missing value. However, .b and .c and .d etc. are also missing values, each one different from the other. So the code is testing to see if nomiss(i) is either .b or .c and then changing the value of nomiss(i) to zero.

 

Seems like a pointless thing to do from my point of view, changing missing to zero, changing other missings to 999 and changing other missings to 9999996, I don't see a benefit, you can test to see when a variable has value .e just as easily as you can test to see if the variable is 9999996; in fact testing to see if a variable has value .e is actually easier, less typing and less chance to make a typographical error than testing to see if a variable is 9999996. Furthermore, leaving the values as missing instead of turning them into an integer allows you to do math properly (things like computing a sum or average) which can't be done if you have 9999996 as the value. However at least now you can understand what the code is doing.

--
Paige Miller
Reeza
Super User
Agreed with Paige regarding that recoding to 9999 is not helpful, you can no longer do summary statistics and calculations on the field now without the risk of skewing your results. Using special missing values is a safer and more user friendly approach.
Reeza
Super User

.A-.Z are special missing values. 

 

For example, if you're doing a survey and someone doesn't answer a question you may want to mark that as missing. But if the question uses skip logic - only some people are asked the question - you may want to identify that differently, so you may code missing because they didn't answer as .A and missing because not asked as .B and missing because of some other reason, .Z

 

Here's the documentation reference on Missing Values

https://documentation.sas.com/?docsetId=lrcon&docsetTarget=p175x77t7k6kggn1io94yedqagl3.htm&docsetVe...

 


@Trishjais wrote:

Dear experts,

can you please help me understand the below code,

I am not getting what .b ,.c is doing in do loop here.

 

data want (rename=(acc_id=acct_id));

set have;

   array nomiss ttl;

   do i=1 to dim(nomiss);

            if nomiss{i} in (.b,.c) then nomiss{i}=0;

            if nomiss{i} in (.d) then nomiss{i}=999;

            if nomiss{i} in (.e) then nomiss{i}=9999996;

   end;

run;

 


 

novinosrin
Tourmaline | Level 20

Very neatly explained by @Reeza . I just can't resist this "must share" priceless classic authored by Sir @Quentin

https://www.lexjansen.com/nesug/nesug01/ps/ps8009.pdf  

Quentin
Super User

Thanks for the kind mention @novinosrin .  That was my first paper, a poster for NESUG because I was way too scared to present anything, but a poster was enough to earn me a ticket to the conference from the good folks I was lucky enough to work with at Westat.

 

Years later I was at a new job, and we were talking about missing data, and someone opened a folder of papers they had downloaded and they had a copy of that paper.  I was so excited and said "wow, great to know someone read my paper", and the head programmer said "relax, just because they downloaded it doesn't mean they read it." : )

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
novinosrin
Tourmaline | Level 20

@Quentin - I was so excited and said "wow, great to know someone read my paper", and the head programmer said "relax, just because they downloaded it doesn't mean they read it." : ) 

 

If "they" didn't, it's their loss in my humble yet very strong opinion. Who's acknowledgement should matter to anoint you as a "genius"? It's none other than Guru Paul D who mentioned to me what a genius you are.

FYI- We were chatting for 2 hours over the phone last week. Just general chat like we talked about almost any random fun topic like weather, cars, Covid, jet engines,music etc but SAS lol, though something came up about SAS in context and he mentioned what a genius you are. Kudos! 

 

 

Quentin
Super User

Paul is just as generous as his praise as you are.

 

I was only lucky to meet Paul and many other SAS notables from SAS-L early in my career, and benefitted greatly from such a welcoming SAS community.

 

I'm constantly amazed by how little I know about SAS, my expertise (as it is) is in small areas, and definitely not keeping up with the growth of SAS languages/platforms.

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 1463 views
  • 8 likes
  • 6 in conversation