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

Hello,

 

I use SAS GUIDE and i want to classify datas by month.

My table is Janv-15 to dec-15...or SAS class by alphabet instead or chronologic...it put avril then august insteal of janvier, février...

What do i have to do?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Since there is no NLS informat that can read the MMMM_YY format that you get, you will have to translate manually be converting the french name to a number, and then use a standard format:

data want;
input date_french $;
format date date9.;
date_french = tranwrd(date_french,'janv','01');
date_french = tranwrd(date_french,'fevr','02');
date = input('01-'!!date_french,ddmmyy8.);
cards;
janv-15
fevr-15
;
run;

View solution in original post

20 REPLIES 20
peter2
Obsidian | Level 7

Hello, here is my table...how can i put this by chronology?

Reeza
Super User

Make sure your dates are SAS dates, so numeric with a date format. Then they'll sort correctly. You may need t create a new variable to do this using INPUT function.

 

 

peter2
Obsidian | Level 7

@Reeza, thanks, i do this but problem :

 

 

3 PROC SQL NOEXEC;

4 SELECT /* mois num */

5 (INPUT(t1.MOIS,CATDFMY)) AS 'mois num'n

_______

22

76

ERROR 22-322: Syntax error, expecting one of the following: un nom de format, ?.

ERROR 76-322: Syntax error, statement will be ignored.

6 FROM WORK.TABLE_DES_MOIS1 t1;

7 QUIT;

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE SQL used (Total process time):

real time 0.00 secondes

cpu time 0.00 secondes

 

8 QUIT; RUN;

9

 

here is my table

 

01/01/2015 janv.-15
02/01/2015 janv.-15
03/01/2015 janv.-15
04/01/2015 janv.-15
05/01/2015 janv.-15
06/01/2015 janv.-15
07/01/2015 janv.-15
08/01/2015 janv.-15
09/01/2015 janv.-15
10/01/2015 janv.-15
11/01/2015 janv.-15
12/01/2015 janv.-15
13/01/2015 janv.-15
14/01/2015 janv.-15
15/01/2015 janv.-15

 

 

peter2
Obsidian | Level 7

@Kurt, thanks but it gimes now

 

1 ;*';*";*/;quit;run;

2 OPTIONS PAGENO=MIN;

 

3 PROC SQL NOEXEC;

4 SELECT /* Mois NUM */

5 (Mois_Num = INPUT(t1.MOIS,ddmmyy10.)) AS 'Mois NUM'n

6 FROM WORK.TABLE_DES_MOIS1 t1;

ERROR: The following columns were not found in the contributing tables: Mois_Num.

7 QUIT;

NOTE: The SAS System stopped processing this step because of errors.

NOTE: PROCEDURE SQL used (Total process time):

real time 0.00 secondes

cpu time 0.00 secondes

 

8 QUIT; RUN;

 

Reeza
Super User

Your calculation s mixing data step and SQL. 

 

Input(..) as 'mois num'n

 

No = or variable name before the Input. 

peter2
Obsidian | Level 7

@Reeza, in fact!!

 

I make a modification

 

INPUT(t1.MOIS,monyy5.)

 

 

 

But it gives me "."

 

 

. 01/01/2015 janv.-15
. 02/01/2015 janv.-15
. 03/01/2015 janv.-15
. 04/01/2015 janv.-15
. 05/01/2015 janv.-15
. 06/01/2015 janv.-15

 

Kurt_Bremser
Super User

@peter2 wrote:

@Reeza, in fact!!

 

I make a modification

 

INPUT(t1.MOIS,monyy5.)

 

 

 

But it gives me "."

 

 

. 01/01/2015 janv.-15
. 02/01/2015 janv.-15
. 03/01/2015 janv.-15
. 04/01/2015 janv.-15
. 05/01/2015 janv.-15
. 06/01/2015 janv.-15

 


monyy. is a standard SAS format and expects English month abbreviations.

For the second column, use ddmmyy10.

peter2
Obsidian | Level 7

in fact, i have OCT2015 & NOV2015....but not for the other month, why?

Kurt_Bremser
Super User

Up to now, you only posted example data for January. Providing more complete example data will make it easier for us to help you.

 

What exactly IS the rule for building your target variable, and what values should it contain? Keep in mind that a SAS date value is a count of the number of days since 01/01/1960 and will always contain a "day part".

Kurt_Bremser
Super User

You need to write correct SQL code, of course. I gave you a data step.

proc sql;
select
  input(t1.mois,ddmmyy10.) as mois_num
from work.table_des_mois t1
;
quit;

Note that I deliberately do not use blanks in variable (or other) names, as they are only a major pain-in-the-ass.

peter2
Obsidian | Level 7

thank you all...

 

@Kurt, here is what i obtain

 

. 25/09/2016 sept.-16
. 26/09/2016 sept.-16
. 27/09/2016 sept.-16
. 28/09/2016 sept.-16
. 29/09/2016 sept.-16
. 30/09/2016 sept.-16
OCT2016 01/10/2016 oct.-16
OCT2016 02/10/2016 oct.-16
OCT2016 03/10/2016 oct.-16
OCT2016 04/10/2016 oct.-16
OCT2016 05/10/2016 oct.-16
OCT2016 06/10/2016 oct.-16
OCT2016 07/10/2016 oct.-16

 

what i want is to get in the first row all months like OCT2016 in the aim to class by chronology.

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 20 replies
  • 3590 views
  • 3 likes
  • 4 in conversation