Have data like (but over 20 variables):
Input X1-X5;
Cards;
20 10 31 23 42
41 32 44 02 11
22 08 34 82 05
10 45 22 09 10
....; /*over 30,000 rows*/
Want certain values to be empty so that the output will look like:
20 31 23 42
41 32 44 11
22 08 82 26
21 45 22 09
...
I tried if X1 in ('09', '10', '11') then X1=' '; It works but I have to type 'if then' for all variables. Would there be any short way to solve the problem?
Thanks in advance.
Sijansap
What kind of rules are involved with setting the missing values? You haven't provided much information. Is it only 9, 10 and 11 that get set to missing or something else? Is the rule exactly the same for all 20 variables or are there different rules for the 20 variables?
If the same rule is applied to multiple variables then likely an array is part of the answer;
data want;
set have;
array x x1-x5;
do i=1 to dim(x);
if x[i] in ('09','10','11') then call missing(x[i]);
end;
drop i;
end;
but if the different variables had different rules then you may not have much luck.
What kind of rules are involved with setting the missing values? You haven't provided much information. Is it only 9, 10 and 11 that get set to missing or something else? Is the rule exactly the same for all 20 variables or are there different rules for the 20 variables?
If the same rule is applied to multiple variables then likely an array is part of the answer;
data want;
set have;
array x x1-x5;
do i=1 to dim(x);
if x[i] in ('09','10','11') then call missing(x[i]);
end;
drop i;
end;
but if the different variables had different rules then you may not have much luck.
Hi BallardW,
Thank you for your quick reply and suggestion. Your suggestion will help me for X1, and whenever X1 through X5 ( in this case) have same rule to missout. With this at least I have more than half way simplified since some variables have the same rule, and some have different. When there is different rule, I will use your technique and give different names to the variables that have different rule.
Thanks again,
Sijansap
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.