Hi guys,
I have a quite simple problem, but I don't have a clue how can I solve it.
I have a macrovariable that contains quotes and ampersand (I need it for the excel file). Take a look at this code:
%macro x; /* ... */ %let string = "This is sample string" & char(10) & "This is second line of sample string"; %put &=string; data x; a=&string; run; %mend; %x;
But the problem is that I don't know how can I add such a string into data set (data x in my sample code). Does anyone have any idea?
Thanks!
Filip
a=symget('string');
a=symget('string');
SYMGET
49 %let string = "This is sample string" & char(10) & "This is second line of sample string";
50 %put &=string;
STRING="This is sample string" & char(10) & "This is second line of sample string"
51
52 data a;
53 x = symget('STRING');
54 put 'NOTE: ' x=;
55 run;
NOTE: x="This is sample string" & char(10) & "This is second line of sample string"
Use the SYMGET function:
data x;
a = symget("string");
run;
If you don't want a length of 200 for your new variable, use a LENGTH statement before the assignment.
Hi all,
Thanks a lot for your replies, that works perfectly! 🙂
Best,
Filip
An aleternative to using symget (a DATA step function that will execute once per iteration of the loop), would be to use a macro quoting function, such as %superq, e.g.:
1 %let string = "This is sample string" & char(10) & "This is second line of sample string"; 2 %put &=string; STRING="This is sample string" & char(10) & "This is second line of sample string" 3 4 data x; 5 a="%superq(string)"; 6 put a= ; 7 run; a="This is sample string" & char(10) & "This is second line of sample string" NOTE: The data set WORK.X has 1 observations and 1 variables.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.