Hello
The calculated column concantenate is not calculated well.
For example:
For first row value should be
M6=2211,M5=2210,M4=2209,M3=2208,M2=2207,M1=2206
But I get value-
M6=2211,M5=2211,M4=2211,M3=2211,M2=2211,M1=2211
Why did it happen?
data Want2(Keep=i M6 M5 M4 M3 M2 M1 _M6_ _M5_ _M4_ _M3_ _M2_ _M1_ caoncantenate);
startdate="01NOV2022"d;
do i = 0 to 58;
M6=intnx('month',startdate,-i);
M5=intnx('month',M6,-1);
M4=intnx('month',M6,-2);
M3=intnx('month',M6,-3);
M2=intnx('month',M6,-4);
M1=intnx('month',M6,-5);
_M6_=put(M6,yymmn4.);
_M5_=put(M6,yymmn4.);
_M4_=put(M6,yymmn4.);
_M3_=put(M6,yymmn4.);
_M2_=put(M6,yymmn4.);
_M1_=put(M6,yymmn4.);
format M6 M5 M4 M3 M2 M1 YYMMn4.;
concantenate=CAT("M6=",_M6_," ,M5=",_M5_," ,M4=",_M4_," ,M3=",_M3_," ,M2=",_M2_," ,M1=",_M1_);/***Why is it not working well???***/
output;
end;
Run;
you are applying format to the same variable, should be:
_M6_=put(M6,yymmn4.);
_M5_=put(M5,yymmn4.);
...
Incorrect spelling.
you are applying format to the same variable, should be:
_M6_=put(M6,yymmn4.);
_M5_=put(M5,yymmn4.);
...
Did you look at your code:
_M6_=put(M6,yymmn4.); _M5_=put(M6,yymmn4.); _M4_=put(M6,yymmn4.); _M3_=put(M6,yymmn4.); _M2_=put(M6,yymmn4.); _M1_=put(M6,yymmn4.);
PUT the same variable 6 times and you get the same value 6 times.
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!
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.