BookmarkSubscribeRSS Feed
gabras
Pyrite | Level 9

Hello,

I need to create multiple conditions in a where statement in a dynamic way.
I'll explain.
Let's say we have:

 

data want;
set have;
where first = "& vala" and second = "& valb" and third = "& valc";
run;

 

Where & val # are values taken from a table with three columns (first, second, third) and a row.

 

How can I do if I want to add one or more lines to the table and make the code in the following way:

 

data want;
set have;
where (first = "& vala1" and second = "& valb1" and third = "& valc1"
   OR first = "& vala2" and second = "& valb2" and third = "& valc2"
   OR first = "& vala #" and second = "& valb #" and third = "& valc #")
run;

 

Thanks for the help.

 

One more question: is there a SAS application which permits the user to modify a table based on some prompt you designed? Such as add rows, upodate a column or something like this?

6 REPLIES 6
Astounding
PROC Star

Are you allowed to sort your data sets?  If so, this becomes a simple match merge and doesn't need any macro language:

 

proc sort data=have;

by first second third;

run;

 

proc sort data=valid_values;

by first second third;

run;

 

data want;

merge have (in=in1) valid_values (in=in2);

by first second third;

if in1 and in2;

run;

gabras
Pyrite | Level 9

Thank you @Astounding

you are right.

 

But the problem is not so simple.

I migth have the case in which i have also the fourth column that i not always need to use in the where condition, such as:

 

 

where first = &valuea1 and second =valueb1 and third=valuec1

   OR first = &valuea2 and second =&valueb2 and third=&valuec2 and fourth= &valued2;

 

 

Astounding
PROC Star

This is nearly as simple.  Presumably you can tell whether you need three variables or four.  If you can't tell, that's another story and takes a little more work.

 

%let varlist=first second third fourth;

 

proc sort data=have;

by &varlist;

run;

proc sort data=valid_values;

by &varlist;

run;

 

data want;

merge have (in=in1) valid_values (in=in2 keep=&varlist);

by &varlist;

if in1 and in2;

run;

 

gabras
Pyrite | Level 9

Hi @Astounding

 

let's say that what you suggested is correct: i have to think if it fits for my case.

 

Is thera a SAS application that permits a user to modify the table valid_values by adding, updating or deleting rows?

 

Thank you

Astounding
PROC Star

Of course.

 

Adding only:  PROC APPEND

 

Deleting / modifying / adding:  a DATA step or PROC SQL

gabras
Pyrite | Level 9

OK

 

I was looking for the SAS AppDev Studio which you can use to develop web application that could permit the end-user to modify table.

 

Thanks 

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!

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