Hi,
This is a data manipulation exercise. I'm trying to use the following data to macrotize the values in 4 out of the 5 variables. I'm new to the arrays, but i'm not sure what i'm doing wrong.
Here is the data:
data have;
infile datalines dsd dlm=",";
input word1 $ word2 $ word3$ word4$ word5$;
datalines;
We, are, here, now., pretzel
;
run;
My code doesn't work. I want to only macrotize the the values from word1 to word4. Thanks
data _null_; set have;
array word[4] word1--word4;
do i=1 to 4;
call symput('word[i]', word[i]);
end;
run;
The desired outcome:
I want to create 4 macro variables that are named the following, "word1", "word2", "word3", "word4", using only the variables word1, word2, word3, word4
Thanks
The first argument of call symput ought to be a text string containing the name of the macro variable you want to create.
call symput('word[i]', word[i]);
creates macro variables with the name of text string in the first argument to call symput, so you are creating macro variables with the (illegal) name of word[i] and so macro variables cannot be created. Instead, you need to make the first argument of call symput a valid text string, such as word1 word2 etc.
call symput(cats('word',i), word[i]);
The first argument, when the loop variable I is equal to 1, cats('word',i) equals word1 so a macro variable named WORD1 is created with the value of word[1]
The first argument of call symput ought to be a text string containing the name of the macro variable you want to create.
call symput('word[i]', word[i]);
creates macro variables with the name of text string in the first argument to call symput, so you are creating macro variables with the (illegal) name of word[i] and so macro variables cannot be created. Instead, you need to make the first argument of call symput a valid text string, such as word1 word2 etc.
call symput(cats('word',i), word[i]);
The first argument, when the loop variable I is equal to 1, cats('word',i) equals word1 so a macro variable named WORD1 is created with the value of word[1]
First thing is that unless you really have a pressing need to insert leading and/or trailing spaces into the macro variables you should not be using ancient CALL SYMPUT() routine. Use CAL SYMPUTX() instead.
You can use CATS() to append the integer to the macro variable name.
call symputx(cats('word',i), word[i]);
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!
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.