BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HB
Barite | Level 11 HB
Barite | Level 11

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??

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

%let myname= "SMITH";

DATA lookup;                          

    SET some_data_file;

  KEEP lname and some other variables;

    WHERE lname =&myname;

RUN;

View solution in original post

4 REPLIES 4
Reeza
Super User

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;

Linlin
Lapis Lazuli | Level 10

%let myname= "SMITH";

DATA lookup;                          

    SET some_data_file;

  KEEP lname and some other variables;

    WHERE lname =&myname;

RUN;

HB
Barite | Level 11 HB
Barite | Level 11

Outstanding!

Astounding
PROC Star

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 4 replies
  • 1613 views
  • 6 likes
  • 4 in conversation