sonmic
asked on
Initialize variables
Hi,
I have a SAS-dataset with 53 variables. When a certain variable is different from zero then i want to set 39 variables (variable 4 to 42) to zero. I can set them one by one to zero, but is there another way?
Tx
sonmic
I have a SAS-dataset with 53 variables. When a certain variable is different from zero then i want to set 39 variables (variable 4 to 42) to zero. I can set them one by one to zero, but is there another way?
Tx
sonmic
ASKER
Hi,
Tx for your answer but i get the message :
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
Tx for your answer but i get the message :
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The best way (I think) is to use an ARRAY statement.
The issue is how to list the variable names in the ARRAY statement. If the variables follow a certain numbering format (say VAR1 VAR2 VAR3 ... VAR53) then the statement can be as follows:
ARRAY ArrName (*) VAR1 - VAR53;
If the variable's are in the correct order in the dataset, then you can use the following code to get a list of variable names into the macro variable &var_names:
proc sql noprint;
select name into : var_names separated by ' '
from dictionary.columns where libname = 'WORK' and memname = 'TEST';
%put &var_names;
Note that WORK and TEST must be in CAPITALS. (TEST is the name of the dataset)
To answer your query, try the following full code:
Open in new window