Hello
User define macro variable in structure as following:
1 or 2 digits number _4 digits number _ 4 digits number
for example:
%let X=59_2001_9901;
%let X=8_2001_9901;
I want to create another macro variable called Y that is created automatically from macro variable X and get the digits of macro variable X before the first underscore.
So in the examples :
%let Y=59;
%let Y=8;
May you show code how to do it please?
Use the SCAN function, wrapped in %SYSFUNC:
%let y = %sysfunc(scan(&x.,1,_));
Or even just:
%let y = %scan(&x.,1,_);
[EDIT:] Link to the doc. https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1nhhymw6gxixvn1johcfl6kaygw.htm
;-D
%let X=59_2001_9901;
%let Y=%sysfunc(scan(&X, 1, _));
%put Y=&Y;
%let X=8_2001_9901;
%let Y=%sysfunc(scan(&X, 1, _));
%put Y=&Y;
?
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 save with the early bird rate—just $795!
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.