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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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.

PG

View solution in original post

8 REPLIES 8
Reeza
Super User

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(*));
howdelicious
Fluorite | Level 6

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, *.

 

PGStats
Opal | Level 21

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.

PG
howdelicious
Fluorite | Level 6

*EDIT*

Actually, I coded in the array incorrectly before. Your solution worked perfectly. Thank you!!!

Reeza
Super User

Do you have any naming convention? If you don't, unfortunately the only way is to manually write them out.

PGStats
Opal | Level 21

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).

PG
howdelicious
Fluorite | Level 6
Hi Reeza and PGStats, the thread has been solved thanks to PGStat's original post.

I mis-coded my array earlier, hence it didn't work. I realised my error and found that PGStat's solution worked perfectly. Thanks for your help!!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1133 views
  • 3 likes
  • 3 in conversation