Desktop productivity for business analysts and programmers

Month Order on sas guide

Accepted Solution Solved
Reply
Contributor
Posts: 31
Accepted Solution

Month Order on sas guide

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


Accepted Solutions
Solution
‎08-04-2016 06:49 AM
Super User
Posts: 7,446

Re: Month Order on sas guide

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;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Super User
Posts: 7,446

Re: Month Order on sas guide

You either have your dates stored as character instead of as SAS date values, or you're sorting by formatted instead of raw values.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 31

Re: Month Order on sas guide

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

Super User
Posts: 19,167

Re: Month Order on sas guide

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.

 

 

Contributor
Posts: 31

Re: Month Order on sas guide

@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

 

 

Super User
Posts: 7,446

Re: Month Order on sas guide

 

data work.new;
set WORK.TABLE_DES_MOIS1;
mois_num = input(MOIS,ddmmyy10.);
run;

Don't forget the dot when using a format.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 31

Re: Month Order on sas guide

@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;

 

PROC Star
Posts: 1,146

Re: Month Order on sas guide

Super User
Posts: 19,167

Re: Month Order on sas guide

Your calculation s mixing data step and SQL. 

 

Input(..) as 'mois num'n

 

No = or variable name before the Input. 

Contributor
Posts: 31

Re: Month Order on sas guide

@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

 

Super User
Posts: 7,446

Re: Month Order on sas guide


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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 31

Re: Month Order on sas guide

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

Super User
Posts: 7,446

Re: Month Order on sas guide

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".

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 7,446

Re: Month Order on sas guide

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 31

Re: Month Order on sas guide

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 20 replies
  • 609 views
  • 3 likes
  • 4 in conversation