BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sarahzhou
Quartz | Level 8

 

Hi, for the marco below

data test;
/*   store="Susan's Office Supplies";*/
   store="Susan's store.";
   call symput('s',store);
run;

%macro readit;
   %if %bquote(&s) ne %then %put *** valid ***;
   %else %put *** null value ***;
%mend readit;
%readit DATA getting_I_want; I_want = SYMGET('readit'); I_want_c = "&readit"; run;

Then I get a result table for GETTING_I_WANT as below:

I_want  I_want_c
             &readit

 

 

However I really wanted to see the message uner I_want and I_want_c be "*** valid ***".

How do I modify my code.

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Adding: if you have SAS 9.4M5 or later, you don't need macro %READIT here, you can use %IF %THEN %ELSE in open code.

 

%if %bquote(&s) ne %then %do; %let readit= *** valid ***; %end;
%else %do; %let readit= *** null value ***; %end;  

 

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Maxim 2: Read the log

 

1     data test;
2     /*   store="Susan's Office Supplies";*/
3        store="Susan's store.";
4        call symput('s',store);
5     run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: Compressing data set WORK.TEST increased size by 100.00 percent.
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.06 seconds


6
7     %macro readit;
8        %if %bquote(&s) ne %then %put *** valid ***;
9        %else %put *** null value ***;
10    %mend readit;
11
12
13    %readit
*** valid ***
14
15    DATA getting_I_want;
16    I_want = SYMGET('readit');
17    I_want_c = "&readit";
WARNING: Apparent symbolic reference READIT not resolved.
18    run;

NOTE: Invalid argument to function SYMGET('readit') at line 16 column 10.
I_want=  I_want_c=&readit _ERROR_=1 _N_=1
NOTE: The data set WORK.GETTING_I_WANT has 1 observations and 2 variables.
NOTE: Compressing data set WORK.GETTING_I_WANT increased size by 100.00 percent.
      Compressed is 2 pages; un-compressed would require 1 pages.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

You have not created a macro variable named &READIT and so your code doesn't work.

 

Here's an alternative that does create a macro variable named &READIT and does work:

 

%macro readit;
   %global readit;
   %if %bquote(&s) ne %then %let readit= *** valid ***;
   %else %let readit= *** null value ***;
%mend readit;

 

--
Paige Miller
PaigeMiller
Diamond | Level 26

Adding: if you have SAS 9.4M5 or later, you don't need macro %READIT here, you can use %IF %THEN %ELSE in open code.

 

%if %bquote(&s) ne %then %do; %let readit= *** valid ***; %end;
%else %do; %let readit= *** null value ***; %end;  

 

--
Paige Miller
Amir
PROC Star

Hi @sarahzhou,

 

Looking at your code, it looks like you are trying to get the result out of the macro readit.

 

Removing %put from readit allows you to execute the macro to populate the fixed string value in the data step.

 

The below code looks like it achieves what you want.

 

I assume there is more to your code than you have shared, as no macro code would really be needed to achieve the same result.

 

data test;
   /* store="Susan's Office Supplies"; */
   store="Susan's store.";
   call symput('s',store);
run;


%macro readit;
   %if %bquote(&s) ne %then *** valid ***;
   %else *** null value ***;
%mend readit;


data getting_I_want;
   I_want = "%readit";
   I_want_c = "%readit";
run;

 

 

 

Thanks & Kind regards,

Amir.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 3 replies
  • 388 views
  • 2 likes
  • 3 in conversation