Hi,
This code is wrong and does not work:
myname= 'SMITH';
DATA lookup;
SET some_data_file;
KEEP lname and some other variables;
WHERE lname = myname;
RUN;
but it shows what I want to do.
I will have multiple reads data grabs and reads and rather than change the value for a variable (in this case lname) in multiple places (even though find and replace is nice!) I'd like to set it once globally outside the scope of the DATA statements (or even PROC statements) and then be able to use it later in those statements.
How is this done??
%let myname= "SMITH";
DATA lookup;
SET some_data_file;
KEEP lname and some other variables;
WHERE lname =&myname;
RUN;
Macro variables.
I've moved the quotes, but where you include them is up to you.
%let myname = SMITH;
DATA lookup;
SET some_data_file;
KEEP lname and some other variables;
WHERE lname = "&myname";
RUN;
%let myname= "SMITH";
DATA lookup;
SET some_data_file;
KEEP lname and some other variables;
WHERE lname =&myname;
RUN;
Outstanding!
On another note, since you plan on running this multiple times you can speed it up by moving KEEP:
data lookup;
set some_data_file (keep=lname and some other variables);
where lname= ...
run;
This will limit which variables get read in. The original program reads in all the variables, and then limits what gets output.
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.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.