BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

Hi guys,

I have a variable that takes different values (char).

In a code written to perform some calculations, the if-then-else loop is used different times to execute operations.

In all if-then-else loops, only variable values in ("the reference date", "the hospitalization date", "the hospitalization status", "the relapse") are considered and not the remaining ones. Is there a way to put those values in a variable so that it is not necessary to specify every time the list of values that should be considered?

 

I mean something like this: %let varlist= .... but in my case I have not variables but values of a variable. 

 

Thank you in advance

 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Amethyst | Level 16

Do you mean something like this:

%let myList=("the reference date", "the hospitalization date", "the hospitalization status", "the relapse");

data _null_;
  do x = "the reference date", "the noref date";
    if x IN &myList. then put "A"; else put "B";
  end;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

2 REPLIES 2
yabwon
Amethyst | Level 16

Do you mean something like this:

%let myList=("the reference date", "the hospitalization date", "the hospitalization status", "the relapse");

data _null_;
  do x = "the reference date", "the noref date";
    if x IN &myList. then put "A"; else put "B";
  end;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Kathryn_SAS
SAS Employee

You could use PROC SQL similar to the following:

146  proc sql noprint;
147   select name into :val_list separated by ','
148   from sashelp.class;
149  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.05 seconds
      cpu time            0.00 seconds


150  %put &val_list;
Alfred,Alice,Barbara,Carol,Henry,James,Jane,Janet,Jeffrey,John,Joyce,Judy,Louise,Mary,Philip,Robert,Ro
nald,Thomas,William

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 320 views
  • 1 like
  • 3 in conversation