BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
raja777pharma
Fluorite | Level 6

Hello ,

 

I am try to take the values from one reference data and if in reference data have varible name then do caluculation otehr wise consider the same value.

 

In below code on line 3 'EOSDY' is the varible , when eosdy is then do caluucate and assing the value to AVISIT.

when(ADY GE 463 and ADY LE 546 ) do ;AVISIT="WEEK 72" ;AWLO=463 ;AWHI=546 ;AWTARGET=505 ;end;
      when(ADY GE 547 and ADY LE 630 ) do ;AVISIT="WEEK 84" ;AWLO=547 ;AWHI=630 ;AWTARGET=589 ;end;
      when(ADY GE ((337+eosdy)/2) and ADY LE eosdy+13 ) do ;AVISIT="EOS" ;AWLO=((337+eosdy)/2) ;AWHI=eosdy+13 ;AWTARGET=eosdy ;end;

Below is input data and program for reference.

 

data input;
input USUBJID $1-21 ADY $22-25 EOSDY $26-29 AWRANGE $30-43 AWLO $44-47	AWHI $48-51;
datalines;
20180109-10911005311 2   187 DAY 2 - 15    2   15
20180109-10911005311 29  187 DAY 16 - 42   16  42
20180109-10911005311 57  187 DAY 43 - 70   43  70
20180109-10911005311 85  187 DAY 71 - 98   71  98
20180109-10911005311 120 187 DAY 99 - 126  99  126
20180109-10911005311 141 187 DAY 127 - 154 127 154
20180109-10911005311 169 187 DAY 155 - 182 155 182
;
run;

/*from this data will take the values from 'WHLO' and 'WHI' and compare the ADY value form input data set 
if WHLO value have varible (EOSDY ) name from input data then do calulate and assinf the AVISIT and and AWTARGET*/
;
data ref_input;
input wtarget $1-4 avisit $5-13 whlo $14-28 whi $29-37;
datalines;
1   BASELINE                1
2   DAY  2   2              15
29  WEEK 4   16             42
57  WEEK 8   43             70
85  WEEK 12  71             98
113 WEEK 16  99             126
141 WEEK 20  127            154
169 WEEK 24  155            182
197 WEEK 28  183            210
225 WEEK 32  211            238
253 WEEK 36  239            266
281 WEEK 40  267            294
309 WEEK 44  295            322
337 WEEK 48  323            378
421 WEEK 60  379            462
505 WEEK 72  463            546
589 WEEK 84  547            630
eos EOS      (337+eosdy)/2) eosdy+13
;
run;

data final;
   attrib AWLO length=8. AWHI length=8. AWTARGET length=8 AVISIT length=$100;
   set input;
   when (USUBJID="20180109-10911005311" ) select;
      when(ADY LE 1 ) do ;AVISIT="BASELINE" ;AWLO=. ;AWHI=1 ;AWTARGET=1 ;end;
      when(ADY GE 2 and ADY LE 15 ) do ;AVISIT="DAY 2" ;AWLO=2 ;AWHI=15 ;AWTARGET=2 ;end;
      when(ADY GE 16 and ADY LE 42 ) do ;AVISIT="WEEK 4" ;AWLO=16 ;AWHI=42 ;AWTARGET=29 ;end;
      when(ADY GE 43 and ADY LE 70 ) do ;AVISIT="WEEK 8" ;AWLO=43 ;AWHI=70 ;AWTARGET=57 ;end;
      when(ADY GE 71 and ADY LE 98 ) do ;AVISIT="WEEK 12" ;AWLO=71 ;AWHI=98 ;AWTARGET=85 ;end;
      when(ADY GE 99 and ADY LE 126 ) do ;AVISIT="WEEK 16" ;AWLO=99 ;AWHI=126 ;AWTARGET=113 ;end;
      when(ADY GE 127 and ADY LE 154 ) do ;AVISIT="WEEK 20" ;AWLO=127 ;AWHI=154 ;AWTARGET=141 ;end;
      when(ADY GE 155 and ADY LE 182 ) do ;AVISIT="WEEK 24" ;AWLO=155 ;AWHI=182 ;AWTARGET=169 ;end;
      when(ADY GE 183 and ADY LE 210 ) do ;AVISIT="WEEK 28" ;AWLO=183 ;AWHI=210 ;AWTARGET=197 ;end;
      when(ADY GE 211 and ADY LE 238 ) do ;AVISIT="WEEK 32" ;AWLO=211 ;AWHI=238 ;AWTARGET=225 ;end;
      when(ADY GE 239 and ADY LE 266 ) do ;AVISIT="WEEK 36" ;AWLO=239 ;AWHI=266 ;AWTARGET=253 ;end;
      when(ADY GE 267 and ADY LE 294 ) do ;AVISIT="WEEK 40" ;AWLO=267 ;AWHI=294 ;AWTARGET=281 ;end;
      when(ADY GE 295 and ADY LE 322 ) do ;AVISIT="WEEK 44" ;AWLO=295 ;AWHI=322 ;AWTARGET=309 ;end;
      when(ADY GE 323 and ADY LE 378 ) do ;AVISIT="WEEK 48" ;AWLO=323 ;AWHI=378 ;AWTARGET=337 ;end;
      when(ADY GE 379 and ADY LE 462 ) do ;AVISIT="WEEK 60" ;AWLO=379 ;AWHI=462 ;AWTARGET=421 ;end;
      when(ADY GE 463 and ADY LE 546 ) do ;AVISIT="WEEK 72" ;AWLO=463 ;AWHI=546 ;AWTARGET=505 ;end;
      when(ADY GE 547 and ADY LE 630 ) do ;AVISIT="WEEK 84" ;AWLO=547 ;AWHI=630 ;AWTARGET=589 ;end;
      when(ADY GE ((337+eosdy)/2) and ADY LE eosdy+13 ) do ;AVISIT="EOS" ;AWLO=((337+eosdy)/2) ;AWHI=eosdy+13 ;AWTARGET=eosdy ;end;
   otherwise;
   end; 
run;

Thank you,

Rajasekhar.

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You can use next macro to check wether the variable exists:

%macro varexist(dsn, var);
   %let dsid=%sysfunc(open(&dsn));
   %if %eval(&dsid) ne 0 %then %do;
	   %if %eval(%sysfunc(varnum(&dsid,&var))) = 0 
	   %then %do;   <your code when variable is absent>; %end;
	   %else %do;   <your code when variable exists>;     %end;
	%end;
%mend varexist;

To be used as in:

%varexist(sashelp.class, sex);

View solution in original post

4 REPLIES 4
Shmuel
Garnet | Level 18

You can use next macro to check wether the variable exists:

%macro varexist(dsn, var);
   %let dsid=%sysfunc(open(&dsn));
   %if %eval(&dsid) ne 0 %then %do;
	   %if %eval(%sysfunc(varnum(&dsid,&var))) = 0 
	   %then %do;   <your code when variable is absent>; %end;
	   %else %do;   <your code when variable exists>;     %end;
	%end;
%mend varexist;

To be used as in:

%varexist(sashelp.class, sex);
raja777pharma
Fluorite | Level 6

Hi ,

Thank you for response.

 

Event i used the maccro , below code is not working to calculate.

 

when(ADY GE ((337+eosdy)/2) and ADY LE eosdy+13 ) do ;AVISIT="EOS" ;AWLO=((337+eosdy)/2) ;AWHI=eosdy+13 ;AWTARGE

Please let me know whre is going mistake.

 

Thank you,

Rajasekhar.

Shmuel
Garnet | Level 18

1) What do you mean by "going mistake" - is there a syntax error or mis calculating?

2) In order to help[ you we need the full code run, better shown in the log within the messegaes.

raja777pharma
Fluorite | Level 6

Hi ,

I have fixed the error .

 

Thank you for help.

 

Thank you,

Rajaskhar.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 567 views
  • 1 like
  • 2 in conversation