I want to run the following code. My problem is that I dont know how to put the delimiter in the scan function so that it identifies the three variables inside vars. I've tried multiple times without success (I just put "?" inside the code because that is were my question lies). I hope you can help me. Thanks in advance.
%let vars="TIIE 28 días (%)"n "TIIE 91 días (%)"n "Cetes 28 días (%)"n;
%macro serie;
%do i=1 %to 3;
%let parameter=%scan(&vars.,&i.,"?");
proc sgplot data=base;
series x=date y=¶meter./ markers;
run;
%end;
%mend;
Use the Q modifier on the %SCAN() call.
128 %let vars="TIIE 28 días (%)"n "TIIE 91 días (%)"n "Cetes 28 días (%)"n; 129 %put %scan(&vars,1,%str( ),q); "TIIE 28 días (%)"n 130 %put %scan(&vars,2,%str( ),q); "TIIE 91 días (%)"n 131 %put %scan(&vars,3,%str( ),q); "Cetes 28 días (%)"n
Use the Q modifier on the %SCAN() call.
128 %let vars="TIIE 28 días (%)"n "TIIE 91 días (%)"n "Cetes 28 días (%)"n; 129 %put %scan(&vars,1,%str( ),q); "TIIE 28 días (%)"n 130 %put %scan(&vars,2,%str( ),q); "TIIE 91 días (%)"n 131 %put %scan(&vars,3,%str( ),q); "Cetes 28 días (%)"n
Thanks a lot! This is exactly what I needed. I'm really really grateful.
Since your values have default delimiters like spaces then you need to construct the variable list with a known character like a pipe character | or some other character that you will absolutely never ever use in a variable name.
%let vars="TIIE 28 días (%)"n|"TIIE 91 días (%)"n|"Cetes 28 días (%)"n; %let v1 = %scan(&vars,1,|); %let v2 = %scan(&vars,2,|); %let v3 = %scan(&vars,3,|); %put &v1.; %put &v2.; %put &v3.;
Please note that since the macro language uses % for functions and such you may have other issues further on. Also, inclusion of characters like comma or & in your variable names is extremely likely to be problematic.
In the long run you would be much better off using standard variable names and use a variable LABEL to provide "nicer" text for output.
@alejandrogrrl wrote:
I was asked not to change the names of the variables.
You will curse the day on which you accepted this stupidity.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.