BookmarkSubscribeRSS Feed
David_Billa
Rhodochrosite | Level 12

Is there a chance to combine the below steps into 2 or 3?

 

%let table_name=test;

data want (keep=flt_id col_nm operant value );
set oper_flt;
where TBL_NM="&table_name";
run;

proc sql noprint;
select catx(' ',col_nm,operant,value)
  into :where separated by ' or '
  from want
;
quit;

proc sql;
create table temp as select * from &table_name
 where &where ;
run;

data oper_flt (keep=flt_id);
set temp;
run;
2 REPLIES 2
gamotte
Rhodochrosite | Level 12

Hello,

 

I don't really understand what the last datastep is for so i ignored it.

 

%let table_name=sashelp.class;

data oper_flt;
    infile cards dlm=',' dsd;
    length table_name $32 col_nm $32 operant $2;
    input flt_id table_name col_nm operant value;
    cards;
1,sashelp.class,age,=,12
1,sashelp.class,weight,ge,90
;
run;

data _NULL_;
    call execute('proc sql noprint; CREATE TABLE want AS SELECT * FROM &table_name. WHERE ');

    do until(fend);
        set oper_flt (where=(table_name="&table_name.")) end=fend;
        call execute(catx(' ', col_nm, operant, value, 'OR'));
    end;
    call execute('0; quit;');
    stop;
run;
Astounding
PROC Star

This is untested, but looks like it should work:

 

%let table_name=test;

proc sql noprint;
select catx(' ',col_nm,operant,value)
  into :where separated by ' or '
  from oper_flt
  where TBL_NM="&table_name";
  ;
create table oper_flt2 as select flt_id from &table_name
  where &where ;
quit;

When I say "should work" it means you have to test it since you have the data.  This code should produce the same result as your original code, except that the final data set name is OPER_FLT2 instead of replacing OPER_FLT.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 738 views
  • 0 likes
  • 3 in conversation