开发者

Substituting the values of a variable in sas

I have a column in my sas file as age and another column as finalage. I want to substitute the values in age column by values in agefinal column for just one ID (that is 5)

The code that I used was:

Data temp;
set temp;
if ID = 5;
then age = agefinal;
run;

I could not substitute the values. The values in age column did not change. I tried to run this code to check the character length of values since character type is numeric for both the columns.

Code:

Proc contents data = temp;
tables age agefi开发者_开发百科nal;
run;

The output that I got was:

age : character length 3.
agefinal: character length $3

I would appreciate your suggestions.


Try removing the semicolon at the end of the if statement. Right now what you're doing is deleting all records where the id isn't equal to five.


Try setting the formats to be the same

data temp;
 modify temp;
 format age agefinal $3.;
 run;

and then see if it will let you do the substitution.


The code you provided runs with an ERROR, remove the additional semicolon and that may fix your issue:

/* ORIGINAL */
Data temp;
set temp;
if ID = 5;
then age = agefinal;
run;

/* CORRECTED */
Data temp;
set temp;
if ID = 5 /* REMOVED SEMICOLON */
then age = agefinal;
run;

Cheers Rob

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜