BookmarkSubscribeRSS Feed
ramtejdasari
Calcite | Level 5

Hi

 

I am working on multiple clinical trials and I am using single program for all these individual trial. I came across with the situation where I need to derive 10 variables using X dataset for all the 3 trials. but unfortunately for one trial I need to derive all these 10 variables using Y dataset. The variables I need to use to derive all these 10 new variables in the dataset X & Y are same but only difference is the dataset names X & Y. How can I write this in a single piece of code to select Y dataset for one trial else select X dataset for other two trials.

 

I am using the below code but it is giving me the observations from the second dataset only.

 

%macro fa;

%if &study = %str(Trial c) %then %do;

data fmh;

set &srcdata..fa;

run;

%end;

%else %do;

data fmh;

set &srcdata..famh;

run;

%end;

%mend;

%fa

 

Thanks for all your time.

2 REPLIES 2
ballardw
Super User

Where do you set the value for &study? Your comparison is case sensitive so if you set &study with something like : %let study=Trial C;

it would not match the value Trial c 

Source and value for &srcdata?

If &srcdata is not a library then your data reference is incorrect. If it already contains a library.dataset then you do not want the second .

 

%let srcdata=work.data;
%let setname = &srcdata..famh;
/*invalid data set name*/
%put setname is &setname.;

%let srcdata=dataset;
%let setname = &srcdata..famh;
/*treats what might be data set name as library*/
%put setname is &setname.;


In general it is not best practice to use values in macro code not explicitly passed as parameters. Your code call does not document the expected values sent to the macro with something like %fa

 

You would be better off using %macro fa (study= , srcdata= ); in the definition and then call as

%fa(study=x, srcdata=lib); or what ever values are being used.

ramtejdasari
Calcite | Level 5

Hi Ballardw

 

we have a separate program like studyauto , where we created macro variables for study and srcdata.

 

I just tried the code by removing %str in the code and it works now.it is related to the &study variable in the studyauto program where we created this.

 

Again thank you so much for your valuable input. It resolved now.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 514 views
  • 0 likes
  • 2 in conversation