BookmarkSubscribeRSS Feed
Filipvdr
Pyrite | Level 9
Hello,

Im building a Stored Process and i have like an ID which can be in 4 tables.

If it is in table A, i want to get the data from table A.
If ti is in table B, i want to get the data from table B,
...

at the moment i'm doing the following but it takes a long time, not efficient enough


/* See which type of data it is - in which EDC table do i find it */

proc sql noprint; select count(*) into:NumberEdcThick from RF300L3.edc_thick where col_ins_id = "&sel_col_ins_id";quit;
%put &NumberEdcThick;

proc sql noprint;
select count(*) into:NumberEdcCd from RF300L3.edc_cd where col_ins_id = "&sel_col_ins_id";quit;
%put &NumberEdcCd;


proc sql noprint; select count(*) into:NumberEdcTxrF from RF300L3.edc_txrf where col_ins_id = "&sel_col_ins_id";quit;
%put &NumberEdcTxrF;




%macro getData;
%if &NumberEdcCd > 0 %then %do;
data out_table;
set RF300L3.edc_cd;
where col_ins_id = "&sel_col_ins_id";
CALL SYMPUT('TYPE', 'EDC_CD - Format');
run;
%end;
%else %if &NumberEdcThick > 0 %then %do;
data out_table;
set RF300L3.edc_thick;
where col_ins_id = "&sel_col_ins_id";
CALL SYMPUT('TYPE', 'THICK - Format');
run;
%end;
%else %if &NumberEdcTxrF > 0 %then %do;
data out_table;
set RF300L3.edc_txrf;
where col_ins_id = "&sel_col_ins_id";
CALL SYMPUT('TYPE', 'TXRF - Format');
run;
%end;
%else %do;
data _null_;
CALL SYMPUT('TYPE', 'General - Format');
run;
%extract_edc_full(pInProcess WaferId User_id State Slot ROW_ID ProcessRecipe ProcessPlan PmProcedure MeasRecipe
MeasKey MainTool LotId LimitsKey InspectionTool Facility DuploWaferId Datim CustomKey
ChecklistActivityId CSIM_TIMESTAMP COL_INS_ID, out_table);
%end;
%mend;
%getData;
2 REPLIES 2
Ksharp
Super User
It looks like you want to set macro variable value when dataset is non-empty.
You can use dictionary table ( dictionary.tables ) to get the number of obs for special tables.
Maybe will save your some time.


Ksharp
GertNissen
Barite | Level 11
Consider adding an index on column "col_ins_id" on your 3 input tables.

In your example you will always be reading first 3 tables + 1 table, another approach would in worst case only read through max 3 tables. If you first query the most likely table, then the other 2 tables might not be used that often. Or you could change the order, so the smallest table is first. Perhaps adding a KEEP statement, when reading would improve the performance (depending on your data)

/* See which type of data it is - in which EDC table do i find it */

%macro getData;
%let type=;
data out_table;
set RF300L3.edc_cd end=theend;
where col_ins_id = "&sel_col_ins_id";
if theend then CALL SYMPUT('TYPE', 'EDC_CD - Format');
run;
%if "&type" ne "" %then %do;
data out_table;
set RF300L3.edc_thick end=theend;
where col_ins_id = "&sel_col_ins_id";
if theend then CALL SYMPUT('TYPE', 'THICK - Format');
run;
%end;
%else %if "&type" ne "" %then %do;
data out_table;
set RF300L3.edc_txrf end=theend;
where col_ins_id = "&sel_col_ins_id";
if theend then CALL SYMPUT('TYPE', 'TXRF - Format');
run;
%end;
%else %do;
data _null_;
CALL SYMPUT('TYPE', 'General - Format');
run;
%extract_edc_full(pInProcess WaferId User_id State Slot ROW_ID ProcessRecipe ProcessPlan PmProcedure MeasRecipe
MeasKey MainTool LotId LimitsKey InspectionTool Facility DuploWaferId Datim CustomKey
ChecklistActivityId CSIM_TIMESTAMP COL_INS_ID, out_table);
%end;
%mend;
%getData;

sas-innovate-2024.png

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.

 

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