BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I woulfd like to know how to bring a column value using macro in Title.

Here is the code where I created the macro using call symput:

Data namesolv;
if "&highselect" NE "ALL" then do;
nameofhigh = INSTITUTION_DESC ;
call symput('highname',nameofhigh);
codeofhigh = 'INSTITUTION' ;
call symput('codehigh',codeofhigh);end;

run;
I am using the macro in title (below )so that I get values from the table for INSTITUTION AND INSTITUTION_DESC IN title .

title;
title1 h=3 "&college" ;
title2 h=3 "Students Who Graduated From High School" ;
title3 h=3 " High School Code: &codehigh Name: &highname " ; title4 h=3 "Enrolled in Term:&period " ;
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi:
There is a HUGE difference between setting a macro variable value inside a data step program and setting a macro variable value with a %LET statement. Generally, when you use a CALL SYMPUT, it is because you want some value from the DATA step program or DATA VALUE from your SET to populate a macro variable. If INSTITUTION_DESC is coming from a SAS dataset, then you need to have a SET statement inside your Data step program, as shown below:
[pre]

%let part = Alf;

data _null_;
set sashelp.class;
where name contains "∂";
call symput('wantname', name);
call symput('theage',put(age,2.0));
call symput('theheight',put(height,2.0));
run;

proc print data=sashelp.class;
title "We really like &wantname";
title2 "He is &theage years old";
title3 "and is already &theheight cm tall";
where name = "&wantname";
run;

[/pre]

The WHERE clause in the data step program ensures that my call symput will ONLY execute for Alfred's record in SASHELP.CLASS. So my call symputs are getting information from Alfred's record and using those values in the CALL SYMPUT statements.

On the other hand, I could have done the test for &PART with %LET statements inside a MACRO program without using a DATA step program. Note in the program below how the comparison for ∂ does NOT have any quotes. I use the default to set a value for &WANTNAME in a %LET statement, then I use &WANTNAME inside a data step program -- because I want to still use information from Alfred's record in the title -- and that information has to come from SASHELP.CLASS dataset.
[pre]
%macro ckalf;
%global wantname theage theheight;

%if ∂ = Alf %then %do;
%let wantname = Alfred;
%end;


data _null_;
set sashelp.class;
where name = "&wantname";
call symput('theage',put(age,2.0));
call symput('theheight',put(height,2.0));
run;
%mend ckalf;

** now invoke the macro program to "check for Alfred";
%ckalf;
run;

proc print data=sashelp.class;
title "2) We really like &wantname";
title2 "2) He is &theage years old";
title3 "2) and is already &theheight cm tall";
where name = "&wantname";
run;

[/pre]

Notice the code with the %IF -- this gives me the ability to test my macro variables inside a MACRO program, not in a Data step program -- this technique will work fine for setting defaults, such as what you want to do with your test. I suspect you test really should be something like this. I am not sure what your data set name is that contains the INSTITUTION_DESC or INSTITUTION variables and I probably have not coded the WHERE clause correctly for your data, but you should be able to get an idea from this code example:
[pre]
** define the macro program;
%macro fixname;
%global highselect;

%if highselect ne ALL %then %do;

Data _null_;
set ??????????????;

where INSTITUTION = "&highselect"; /* if INSTITUTION is character */
** OR pick only one of these where clauses;
where INSTITUTION = &highselect ; /* if INSTITUTION is numeric */

call symput('highname',INSTITUTION_DESC );
call symput('codehigh',INSTITUTION);
run;

*** more code here to do your report for one INSTITUTION;
*** but this code will have your title statements with the references for &HIGHNAME and &CODEHIGH;
title1 h=3 "&college" ;
title2 h=3 "Students Who Graduated From High School" ;
title3 h=3 " High School Code: &codehigh Name: &highname " ;
title4 h=3 "Enrolled in Term:&period " ;
proc print data=???????;
where INSTITUTION = &highselect ;
run;
%end;
%else %if &highselect eq ALL %then %do;
*** code here to execute when highselect eq ALL;
%end;
%mend fixname;

** now invoke the macro program;
%fixname;
[/pre]

For more help with SAS macro programming and the correct way to test or reset macro variable values or to set them with CALL SYMPUT, your best bet is to contact SAS Tech Support.

cynthia
deleted_user
Not applicable
Thank you so much. I did not realise that I do not have a set statement in my data set . Now I got my report working with the INSTITUTION NAME AND CODE VALUES showing in the Title.

Your explanations ON MACROS, will help me understand macros better especially using the double quotes aroud macros.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 634 views
  • 0 likes
  • 2 in conversation