Hi,
I have a dataset with a bunch of variables: a1-a20 (i.e. a1, a2, ... a20), b1-b10, c1-c10.
All of the variables have the same attributes (all numeric): 1 = yes, 2 = no, 3 = don't know.
Is there a quick way to change all the variables, such that whenever the value is 3, it is set to missing, for all variables in the dataset?
Thanks!
the dataset looks like this:
a1 a2 a3... b1
1 2 1 ...3
etc.
Your variable names cannot form numbered variable lists but you can simply use
array letters{*} a1_1 -- d10;
do i = 1 to dim(letters);
if letters{i} = 3 then call missing(letters{i});
end;
where a1_1 and d10 are respectively the first and last of your three-valued variables.
I'm not 100% sure what you're after, but you'll most likely be looking for an array, call missing() routine and whichn().
Something like this if I understand your requirements.
array letters(*) a1-a10 b1-b10 c1-c10; if whichn(3, of letters(*))>0 then call missing (of letters(*));
Hi Reeza,
Thanks for your reply. I am thinking of an array to change the values.
Essentially, I have several hundred numeric variables, where 1 = yes, 2 = no, 3 = don't know.
I wish to change all the '3's to missing.
Here are some examples of variable names that I have:
a1_1-a1_8
b1_1-b1_9
b1n2_1-b1n2_7
c1n3_1-c1n3_9
d1-d10
The issue is that when I tried using an array, it wouldn't read in the variables "a1_1-a1_8". It comes up with an error saying:
Syntax error, expecting one of the following: an integer constant, *.
Your variable names cannot form numbered variable lists but you can simply use
array letters{*} a1_1 -- d10;
do i = 1 to dim(letters);
if letters{i} = 3 then call missing(letters{i});
end;
where a1_1 and d10 are respectively the first and last of your three-valued variables.
*EDIT*
Actually, I coded in the array incorrectly before. Your solution worked perfectly. Thank you!!!
Do you have any naming convention? If you don't, unfortunately the only way is to manually write them out.
If your variables names appear sequentially in the dataset variable list then their names and order doesn't matter. The firstOne--lastOne list will include all variables in between those two, as long as they are of the same type (numeric or character).
And if you want to explicitly specify numeric only
firstvar-numeric-lastvar
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.