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;
.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
@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;
@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.
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.
.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
@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;
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." : )
@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!
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.
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!
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.