BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

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;
 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

you are applying format to the same variable, should be:

_M6_=put(M6,yymmn4.);
_M5_=put(M5,yymmn4.);
...

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Incorrect spelling.

--
Paige Miller
yabwon
Onyx | Level 15

you are applying format to the same variable, should be:

_M6_=put(M6,yymmn4.);
_M5_=put(M5,yymmn4.);
...

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ballardw
Super User

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 675 views
  • 2 likes
  • 4 in conversation