DATA Step, Macro, Functions and more

How to assign the values of the existing variable to a new variable with modification?

Accepted Solution Solved
Reply
Contributor
Posts: 24
Accepted Solution

How to assign the values of the existing variable to a new variable with modification?

Hi, 

 

I am writting a program and want to assign the values of the existing variable to a new variable with some modification, but have a problem with it. the new variable VISNUMEN has the missing value. Any help is greatly appreciated. the coding is as the following:

 

	if VISITNUM=13 and strip(upcase(DSTERM))='PROTCOL COMPLETED' then VISNUMEN=12;
	else if VISITNUM=12 and strip(upcase(DSTERM))='PROTCOL COMPLETED' then VISNUMEN=VISITNUM;

Thanks!


Accepted Solutions
Solution
‎06-15-2017 06:54 PM
Super User
Posts: 19,851

Re: How to assign the values of the existing variable to a new variable with modification?

Fix these two issues and you'll solve your problem:

NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).
71:34 72:39
NOTE: Variable DSTERM is uninitialized.
 
VISITNUM is likely character so you should have the values in quotes in the IF.
DSTERM is not a variable in your dataset so your condition is never met, so all values are missing.
 
Read your log. 

View solution in original post


All Replies
Super User
Posts: 19,851

Re: How to assign the values of the existing variable to a new variable with modification?

It has all missing values or some missing values? Are you sure all conditions are being capture by your logic?

 

The easiest way to check something like this is to use a PROC FREQ with the new and old values.

 

proc freq data=have;
where strip(upcase(dsterm)) = 'PROTOCOL COMPLETED' ;

table visitnum*visnumen;

run;
Contributor
Posts: 24

Re: How to assign the values of the existing variable to a new variable with modification?

Thanks Reeza for the response. Yes, it is all missing values.

Contributor
Posts: 24

Re: How to assign the values of the existing variable to a new variable with modification?

Here the coding purpose is to change the vaule of '13' for VISITNUM to the vaule of '12' of VISNUMEN. it seems that this did not work

Super User
Posts: 19,851

Re: How to assign the values of the existing variable to a new variable with modification?

1. What does your log say?

2. What's the type and format of visitnum

Contributor
Posts: 24

Re: How to assign the values of the existing variable to a new variable with modification?

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
55
56 data ds;
57 set sdtm.ds(rename=(DSDECOD=DSDECOD_ DSTERM=DSTERM_));
58
59 where strip(upcase(DSCAT))='DISPOSITION EVENT';
60
61 length DCDECOD $27 DCREASCD $50 DISCONFL DSRAEFL $1 VISNUMEN 8.;
62 DCDECOD=DSDECOD_;
63 DCREASCD=DSTERM_;
64
65 if strip(upcase(DSDECOD_))^='COMPLETED' then DISCONFL='Y';
66 else DISCONFL='';
67
68 if strip(upcase(DSDECOD_))='ADVERSE EVENT' then DSRAEFL='Y';
69 else DSRAEFL='';
70
71 if VISITNUM=13 and strip(upcase(DSTERM))='PROTCOL COMPLETED' then VISNUMEN=12;
72 else if VISITNUM=12 and strip(upcase(DSTERM))='PROTCOL COMPLETED' then VISNUMEN=VISITNUM;
73
74 keep USUBJID DCDECOD DCREASCD DISCONFL DSRAEFL DSSTDTC VISNUMEN;
75 label DCDECOD='Standardized Disposition Term'
76 DCREASCD='Reason for Discontinuation'
77 DISCONFL='Did the Subject Discontinue the Study?'
78 DSRAEFL='Discontinued due to AE?'
79 VISNUMEN='End of Trt Visit (Vis 12 or Early Term.)'
80 ;
81 run;
 
NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).
71:34 72:39
NOTE: Variable DSTERM is uninitialized.
NOTE: There were 306 observations read from the data set SDTM.DS.
WHERE STRIP(UPCASE(DSCAT))='DISPOSITION EVENT';
NOTE: The data set WORK.DS has 306 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.27 seconds
cpu time 0.23 seconds
 
 
Solution
‎06-15-2017 06:54 PM
Super User
Posts: 19,851

Re: How to assign the values of the existing variable to a new variable with modification?

Fix these two issues and you'll solve your problem:

NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).
71:34 72:39
NOTE: Variable DSTERM is uninitialized.
 
VISITNUM is likely character so you should have the values in quotes in the IF.
DSTERM is not a variable in your dataset so your condition is never met, so all values are missing.
 
Read your log. 
PROC Star
Posts: 326

Re: How to assign the values of the existing variable to a new variable with modification?

you may need to give a else statement. If you can do not give else statement, then you will get null if scenarious you have mentioned does not cover all the records. you should probably do else varnum = somevalue

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 177 views
  • 0 likes
  • 3 in conversation