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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.