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

dear SAS experts,

 

I use this Code:

 

* Neues Format für die Berechnung der Durchschnitte für n Monate ;
proc format;
value ytd (multilabel) 
1							='Jan'
1,2							='Feb' 
1,2,3						='Mar'
1,2,3,4						='Apr'
1,2,3,4,5					='Mai'
1,2,3,4,5,6					='Jun'
1,2,3,4,5,6,7				='Jul'
1,2,3,4,5,6,7,8				='Aug'
1,2,3,4,5,6,7,8,9			='Sep'
1,2,3,4,5,6,7,8,9,10		='Oct'
1,2,3,4,5,6,7,8,9,10,11		='Nov'
1,2,3,4,5,6,7,8,9,10,11,12	='Dec'
; 
run;

proc format;
value miz 
1	=	'Jan'
2	=	'Feb' 
3	= 	'Mar'
4	=	'Apr'
5	=	'Mai'
6	=	'Jun'
7	=	'Jul'
8	=	'Aug'
9	=	'Sep'
10	=	'Oct'
11	=	'Nov'
12	=	'Dec'
; 
run;

* Berechnung der monatlichen Summen, FIL Ebene ;
proc summary data=Dashboard_Primaerdaten nway;  
class marktregion_bt nlbez_bt mbrbez_bt filbez_bt FILHB_BT jahr ;
class monat ;
var  ORB: NGS: DrK: ;
output out=FIL1 sum=;
run;
proc sort data=FIL1; by marktregion_bt nlbez_bt mbrbez_bt filbez_bt FILHB_BT jahr monat; run;
data FIL2 (drop=Monat);
set FIL1;
format monat miz.;
Monat_2 = cats(jahr,monat,'Somme');
run;

* Berechnung der monatlichen Durchschnitte, FIL Ebene ;
proc summary data=FIL1 nway;
    class marktregion_bt nlbez_bt mbrbez_bt filbez_bt FILHB_BT jahr;
	class monat/mlf;
    var ORB: NGS: DrK: ;
    output out=FIL3 mean=;
    format monat ytd.;
run;
data FIL3 (drop=monat);
set FIL3;
Monat_2 = cats(jahr,monat,'Moy');
run;

* Berechnung der jährlichen Summen, FIL Ebene ;
proc summary data=Dashboard_Primaerdaten nway;  
class marktregion_bt nlbez_bt mbrbez_bt filbez_bt FILHB_BT jahr ;
var  ORB: NGS: DrK: ;
output out=FIL4 sum=;
run;
data FIL4;
set FIL4;
Monat_2 = cats(jahr,'Jahr');
run;

The variable Monat is numeric and has values from 1 to 12. My Problem is the result of MONAT_2.

In the dataset FIL2 I get the following : 20201Somme (Year = 2020, Month = 1)

In the Dataset FIL3 I get the following: 2020JanMoy

I would like the result in FIL2 to be similar to : 2020JanSomme (instead of 20201Somme)

 

What should I modify to obtain this result?

 

Regards

PY

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

try:

Monat_2 = cats(jahr,put(monat,miz.),'Somme');

it looks like you have a situation like in this example:

data _null_;
 a = 10;
 b = 20;
 format a b date9.;
 c=cats(a,b);
 put _all_;
run;

Bart

_______________
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

2 REPLIES 2
yabwon
Onyx | Level 15

try:

Monat_2 = cats(jahr,put(monat,miz.),'Somme');

it looks like you have a situation like in this example:

data _null_;
 a = 10;
 b = 20;
 format a b date9.;
 c=cats(a,b);
 put _all_;
run;

Bart

_______________
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

In the dataset FIL2 I get the following : 20201Somme (Year = 2020, Month = 1)

In the Dataset FIL3 I get the following: 2020JanMoy

I would like the result in FIL2 to be similar to : 2020JanSomme (instead of 20201Somme)

 

What should I modify to obtain this result?

 

If you look at the two data steps you should see the only difference in FIL2 is the format assigned to monat

Don't use the format. the CAT functions will use the assigned format for variables.

 

 

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!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 413 views
  • 1 like
  • 3 in conversation