Hi all,
I'd like to now if is it possible take a substr from the variable macro's name.
Something like that:
%let Test = 0
Now, I'd like to do a substr from the name "Test", Is it possible ?
Tk's in advanced!
Hi,
you can use the substr function to extract the part of the string. however when you use the sas function in macro variable we should use %sysfunc(). like below
%let test=%str(good day);
%put &test;
%let first=%sysfunc(substr(&test,1,4));
%put &first;
However for your question as per the post you should change the code this way
%let test=0;
%put &test;
%let first=%sysfunc(substr(&test,1,1));
%put &first;
Thanks,
Jagadish
Hi,
you can use the substr function to extract the part of the string. however when you use the sas function in macro variable we should use %sysfunc(). like below
%let test=%str(good day);
%put &test;
%let first=%sysfunc(substr(&test,1,4));
%put &first;
However for your question as per the post you should change the code this way
%let test=0;
%put &test;
%let first=%sysfunc(substr(&test,1,1));
%put &first;
Thanks,
Jagadish
You can substring the variable name, but you'd need to know it before hand.
%let test=0;
%put &test;
%let first=%sysfunc(substr(test,1,1));
%put &first;
If you're looking to substring the value of your macro variable then Jagadish's solution will work.
Yes, the macro language has a %substr function.
%Let Mvar = value;
%Let part = %substr(&Mvar,1,2);
%put note: part: &Part.;
note: part: va
The way I read your Q you want to get a substring of a macro variable name;
that does not compute. What could you do with that info?
Ron Fehd macro maven
Hi, This could be completely off-topic without knowing your purpose. But SAS stores all of the Macro variable name in : dictionary.macros (only for sql) or sashelp.vmacro. From there you can just treat them as regular text strings and apply many powerful parsing functions.
Haikuo
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.