This works.
%put %substr(CHAR_DATA,1,4);
But when used in DATA step it does not work.
data check; var=%substr(CHAR_DATA,1,4); run; ******* or *********; %macro test; data check; var=%substr(CHAR_DATA,1,4); run; %mend test; %test
Thanks for explanation.
The statement works, but it doesn't do what you are expecting. Macro language is not processing your data. It has an entirely different function. It generates the SAS language statements that will then process your data. So this statement is legal:
%let newvar = %substr(CHAR_VAR, 1, 4);
It gives &NEWVAR the value CHAR (the first four characters in "CHAR_VAR").
That means that %SUBSTR works, and gives you a program that looks like this:
data check;
var = CHAR;
run;
Probably, this is not the program that you intended to generate. So work backwards. Start with what you would like to see as a SAS program, and then see where macro language might be able to help you get there.
Good luck.
The statement works, but it doesn't do what you are expecting. Macro language is not processing your data. It has an entirely different function. It generates the SAS language statements that will then process your data. So this statement is legal:
%let newvar = %substr(CHAR_VAR, 1, 4);
It gives &NEWVAR the value CHAR (the first four characters in "CHAR_VAR").
That means that %SUBSTR works, and gives you a program that looks like this:
data check;
var = CHAR;
run;
Probably, this is not the program that you intended to generate. So work backwards. Start with what you would like to see as a SAS program, and then see where macro language might be able to help you get there.
Good luck.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.