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

I have the following code:

PROC SQL;                                   
 SELECT SYSTEM,                             
        PUT(DATE,YYMMD7.) AS DATE,          
        ACCOUNT1,                           
        TYPETASK,                           
        SUM(CPUTOTTM) AS CPUSECS,           
        SUM(CPUZIPTM) AS ZIPSECS            
   FROM USER.TMPSMF                         
  WHERE TYPETASK IN ('JOB','TSU') AND       
        ACCOUNT1 IN ('HHS000V8',            
                     'PG83BAKT',            
                     'PVVABBKZ',            
                     'RF2JS4AR',            
                     'RGGS7PAA',            
                     'RGXP44AY',            
                     'THAFRCKC',            
                     'TJDBA6GA',            
                     'TJNCJLGF',            
                     'RM9ZYWLG')            
  GROUP BY SYSTEM, DATE, ACCOUNT1, TYPETASK;
QUIT;                                       
RUN;                                        

I am trying to group by date in MMYYYY but it's not working and I don't understand why. I've tried several different formats. Do I need to set the format before I perform this SQL call?

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You must tell SAS which version of DATE you are talking about in your group by clause. Try

 

PROC SQL;                                   
 SELECT SYSTEM,                             
        PUT(DATE,YYMMD7.) AS DATE,          
        ACCOUNT1,                           
        TYPETASK,                           
        SUM(CPUTOTTM) AS CPUSECS,           
        SUM(CPUZIPTM) AS ZIPSECS            
   FROM USER.TMPSMF                         
  WHERE TYPETASK IN ('JOB','TSU') AND       
        ACCOUNT1 IN ('HHS000V8',            
                     'PG83BAKT',            
                     'PVVABBKZ',            
                     'RF2JS4AR',            
                     'RGGS7PAA',            
                     'RGXP44AY',            
                     'THAFRCKC',            
                     'TJDBA6GA',            
                     'TJNCJLGF',            
                     'RM9ZYWLG')            
  GROUP BY SYSTEM, calculated DATE, ACCOUNT1, TYPETASK;
QUIT;     
PG

View solution in original post

7 REPLIES 7
Reeza
Super User

@G_I_Jeff wrote:

but it's not working and I don't understand why.

 


What does not working mean?

G_I_Jeff
Obsidian | Level 7

Sorry Reeza,

 

You're right. I forgot to pose my underlying question.

 

It's not sorting the date as MMYYYY. Its still sorting as YYYYMMDD.

 

Jeff

ballardw
Super User

Describe not working, no result, unexpected result, error?

 

Also, is your date actuall a SAS date value and not perhaps a DATETIME value? If your value is date time value then you would see results like ******* as you are trying to put the number seconds into a layout expecting numbers of days.

G_I_Jeff
Obsidian | Level 7

It is a DATETIME observation I'm pulling DATEPART from.

 

I'm trying to group the data by Month/Year based off the only date.

Sven111
Pyrite | Level 9

My PROC SQL is a bit rusty since I've been primarily working with explicit pass through SQL to Oracle, but try something like this.

 

Looks like PG Stats suggested basically the same thing.

 

PROC SQL;                                   
 SELECT SYSTEM,                             
        PUT(DATE, mmyy7.) AS DATE,       
        ACCOUNT1,                           
        TYPETASK,                           
        SUM(CPUTOTTM) AS CPUSECS,           
        SUM(CPUZIPTM) AS ZIPSECS            
   FROM USER.TMPSMF                         
  WHERE TYPETASK IN ('JOB','TSU') AND       
        ACCOUNT1 IN ('HHS000V8',            
                     'PG83BAKT',            
                     'PVVABBKZ',            
                     'RF2JS4AR',            
                     'RGGS7PAA',            
                     'RGXP44AY',            
                     'THAFRCKC',            
                     'TJDBA6GA',            
                     'TJNCJLGF',            
                     'RM9ZYWLG')            
  GROUP BY SYSTEM, PUT(DATE, mmyy7.), ACCOUNT1, TYPETASK;
QUIT;        

 

 

PGStats
Opal | Level 21

You must tell SAS which version of DATE you are talking about in your group by clause. Try

 

PROC SQL;                                   
 SELECT SYSTEM,                             
        PUT(DATE,YYMMD7.) AS DATE,          
        ACCOUNT1,                           
        TYPETASK,                           
        SUM(CPUTOTTM) AS CPUSECS,           
        SUM(CPUZIPTM) AS ZIPSECS            
   FROM USER.TMPSMF                         
  WHERE TYPETASK IN ('JOB','TSU') AND       
        ACCOUNT1 IN ('HHS000V8',            
                     'PG83BAKT',            
                     'PVVABBKZ',            
                     'RF2JS4AR',            
                     'RGGS7PAA',            
                     'RGXP44AY',            
                     'THAFRCKC',            
                     'TJDBA6GA',            
                     'TJNCJLGF',            
                     'RM9ZYWLG')            
  GROUP BY SYSTEM, calculated DATE, ACCOUNT1, TYPETASK;
QUIT;     
PG
G_I_Jeff
Obsidian | Level 7

Thank you! I didn't realize you could/had to put the calculated function or the format in the actual GROUP statement. Now I know!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 984 views
  • 0 likes
  • 5 in conversation