BookmarkSubscribeRSS Feed
soujik
Calcite | Level 5

CHECK dataset created before , but why below bolded step for

 

data _NULL_;
set CHECK;
call symput ('CHECK',CHECK);
run;

9 REPLIES 9
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
soujik
Calcite | Level 5

Hey, thank you... you mean like below

 

data _NULL_;
set CHECK;
call symput ('CHECK',CHECK);
run;

%put & = check;

PaigeMiller
Diamond | Level 26

You seem to have put spaces before and after the equal sign in the %put statement, which is not correct.

--
Paige Miller
soujik
Calcite | Level 5

thank you I got some number(xxxxx), but i want this number in date format (like 22NOV2023)

in log I see CHECK= XXXXX

 

PaigeMiller
Diamond | Level 26

More explanation is needed. What are you going to do with this macro variable CHECK?

--
Paige Miller
soujik
Calcite | Level 5

I want to see variable value in log 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Tom
Super User Tom
Super User

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 
Tom
Super User Tom
Super User

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: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1441 views
  • 0 likes
  • 3 in conversation