CHECK dataset created before , but why below bolded step for
data _NULL_;
set CHECK;
call symput ('CHECK',CHECK);
run;
This bolded step creates a macro variable named CHECK that contains the value of the data set variable named CHECK.
You can have the value of the macro variable CHECK written to the log by running this line of code after the data step.
%put &=check;
Hey, thank you... you mean like below
data _NULL_;
set CHECK;
call symput ('CHECK',CHECK);
run;
%put & = check;
You seem to have put spaces before and after the equal sign in the %put statement, which is not correct.
thank you I got some number(xxxxx), but i want this number in date format (like 22NOV2023)
in log I see CHECK= XXXXX
More explanation is needed. What are you going to do with this macro variable CHECK?
I want to see variable value in log
The %PUT statement shows you the value of the variable. Please be generous with information ... please explain more about what you are going to do with the macro variable &CHECK. Please explain, in detail, what happens with this macro variable after this in your code. Please don't make me ask repeatedly for more information.
The number used to store the date '22NOV2023'd is 23,336. So having a value like 23336 in the macro variable means you can use it to compare to other date values.
Example:
3179 data _null_; 3180 date='22NOV2023'd; 3181 put date=; 3182 call symput('date1',date); 3183 call symputX('date2',date); 3184 run; NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 3182:23 date=23336 NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 3185 3186 %put &=date1 &=date2; DATE1= 23336 DATE2=23336
Notice how using the ancient CALL SYMPUT() method generates extra leading spaces in the macro variable and also ugly notes in the SAS log about converting numbers to characters.
If you would like the string 22NOV2023 written into the macro variable then tell SAS to convert the date using the DATE9. format.
data _null_;
set check;
call symputx('check',put(check,date9.));
run;
But note that if you wanted to use &CHECK to compare to other date values you will need to add quotes and the letter d.
where mydate <= "&check"d
The step will store the last value of the variable CHECK read from the dataset CHECK into the macro variable named CHECK.
Note that along the way it will also store all of the other values of CHECK into the macro variable, but they will be replaced by the value written later. So only the value from the last observation will be available after the data step ends.
NOTE: You almost never want to use the ancient CALL SYMPUT() method. Instead use the modern (its only been available for about 30 years) CALL SYMPUTX() method instead. The only reason to use CALL SYMPUT() is if you really need to have leading and/or trailing spaces written into the macro variable.
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.