View previous topic :: View next topic
|
Author |
Message |
pranavaraj
New User
Joined: 03 Jan 2007 Posts: 15 Location: US
|
|
|
|
Hi,
Is there a way to get the jobname and number using SAS program? I need to generate a report that should have the jobname and number of the job that generated that report.
Am an amateur in SAS programming. Could someone please help? |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Why is it so important to have the jobname and job number ?
Dare I ask if this is a homework assignment ?
You can find out which 'automatic' variables are available by
%put _AUTOMATIC_;
If unavailable, then it is time to start chasing down system control blocks. Good Luck |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Found this code. Maybe it'll work for you:
Code: |
//SASSTEP EXEC SAS
//SYSIN DD *
DATA _NULL_;
LENGTH JOBNAME $8 PROCSTEP $8 STEPNAME $8 PROGNAME $8
JOBNUMBR $8 JOBID $5 USERID $8;
TIOTPTR = PEEK(PEEK(540)+12);
JOBNAME = PEEKC(TIOTPTR,8);
PROCSTEP = PEEKC(TIOTPTR+8,8);
STEPNAME = PEEKC(TIOTPTR+16,8);
JSCBPTR = PEEK(PEEK(540)+180);
PROGNAME = PEEKC(JSCBPTR+360,8);
SSIBPTR = PEEK(JSCBPTR+316);
JOBNUMBR = PEEKC(SSIBPTR+12,8);
JOBID = PEEKC(SSIBPTR+15,5);
JCTPTR = PEEK(JSCBPTR+260);
JOBCLASS = PEEKC(JCTPTR+47,1);
MSGCLASS = PEEKC(JCTPTR+22,1);
USERID = PEEKC(PEEK(PEEK(548)+108)+192,8);
CALL SYMPUT('JOBNAME', JOBNAME);
CALL SYMPUT('PROCSTEP', PROCSTEP);
CALL SYMPUT('STEPNAME', STEPNAME);
CALL SYMPUT('PROGNAME', PROGNAME);
CALL SYMPUT('JOBID', JOBID);
CALL SYMPUT('JOBCLASS', JOBCLASS);
CALL SYMPUT('MSGCLASS', MSGCLASS);
CALL SYMPUT('USERID', USERID);
PUT 'JOBNAME=' JOBNAME;
PUT 'JOBID=' JOBID;
PUT 'STEPNAME=' STEPNAME;
PUT 'PROCSTEP=' PROCSTEP;
PUT 'PROGNAME=' PROGNAME;
PUT 'JOBCLASS=' JOBCLASS;
PUT 'MSGCLASS=' MSGCLASS;
PUT 'USERID=' USERID;
RUN;
/*
|
|
|
Back to top |
|
|
pranavaraj
New User
Joined: 03 Jan 2007 Posts: 15 Location: US
|
|
|
|
Thanks to you both.
Hi Expat,
This isn't homework assignment . Actually we are sending a daily report to the end user and that report was generated using SAS. Sometimes they will comeback and ask questions about the report. So to track down the date the report was generated we are including the jobname and number in the report.
And in %put _AUTOMATIC_; i was able to get the job name and not the job number
Hi superk,
Your code works perfectly. And am going to incorporate the same in the code. Thx so much
Another question reg SAS please... Is there a way to call any assembler routine in SAS program? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Look on the SAS site for CALL MODULE -- you can invoke external programs from within SAS via this mechanism. There are some restrictions and warnings depending on which release of SAS you're using. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Quote: |
So to track down the date the report was generated we are including the jobname and number in the report. |
Would it not be easier to use the date and time displayed at the top of each page rather than include code to give you information that does not reflect the date and time of report generation. |
|
Back to top |
|
|
pranavaraj
New User
Joined: 03 Jan 2007 Posts: 15 Location: US
|
|
|
|
expat wrote: |
Quote: |
So to track down the date the report was generated we are including the jobname and number in the report. |
Would it not be easier to use the date and time displayed at the top of each page rather than include code to give you information that does not reflect the date and time of report generation. |
Yes. But not everyone knows that this report is generated out of that particular JCL. So to have a better understanding, we are including the Job name and number. |
|
Back to top |
|
|
pranavaraj
New User
Joined: 03 Jan 2007 Posts: 15 Location: US
|
|
|
|
Hi,
Actually the report is generated out of TABULATE proc and am not able to incorporate the above mentioned piece of code (by superk) in that.
Here's my code,
OPTIONS MPRINT MLOGIC SYMBOLGEN LINESIZE=80 PAGESIZE=75;
OPTIONS ERRORS=1 NONUMBER PAGESIZE=74 MISSING = '0';
*;
PROC FORMAT;
VALUE $ACT
'ORD' = 'ORDER'
'PAY' = 'PAYMENT'
'CAN' = 'CANCEL';
DATA TRAN;
INFILE INRPT;
FORMAT ENTRDATE MMDDYY8.;
INPUT @221 ENTRDATE PDJULI4.
@233 ACTIVITY $3.
@1081 EFFKEY $6.;
LENGTH JOBNAME $8 JOBNUMBR $8 JOBID $5;
PROC PRINTTO UNIT=17;
PROC SORT DATA=TRAN;
BY EFFKEY;
PROC TABULATE DATA=TRAN FORMAT=COMMA9.0;
CLASS EFFKEY;
TABLE (EFFKEY='ORDERS FROM THIS FILE') ALL , N
/ CONDENSE MISSTEXT=' ';
KEYLABEL N = 'COUNTS'
ALL = 'TOTAL';
TITLE 'FILES RECEIVED ON';
RUN;
TIOTPTR = PEEK(PEEK(540)+12);
JOBNAME = PEEKC(TIOTPTR,8);
CALL SYMPUT('JOBNAME', JOBNAME);
PUT 'JOBNAME=' JOBNAME;
PROC PRINT DATA=_NULL_;
TITLE 'FITNESS DATA';
RUN;
and am receiving error msg as,
"Statement is not valid or it is used out of proper order"
after the TIOTPTR = PEEK(PEEK(540)+12) statement.
Am sure that am doing something very wrong or trying something which is not possible. But am not able to decode it. I tried to google it and solve it but in vain. Could someone please help? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Try this:
Code: |
DATA _NULL_ ;
TIOTPTR = PEEK(PEEK(540)+12);
JOBNAME = PEEKC(TIOTPTR,8); |
These statements you have are part of the DATA step and cannot be placed willy-nilly in the program -- or you'll get a syntax error about the statement being out of the proper order (as you found). |
|
Back to top |
|
|
pranavaraj
New User
Joined: 03 Jan 2007 Posts: 15 Location: US
|
|
|
|
Thanks Robert.
That worked. But i need to get the jobname and number in the report. So i used a Print proc to get that.
So after this
PROC TABULATE DATA=TRAN FORMAT=COMMA9.0;
CLASS EFFKEY;
TABLE (EFFKEY='ORDERS FROM THIS FILE') ALL , N
/ CONDENSE MISSTEXT=' ';
KEYLABEL N = 'COUNTS'
ALL = 'TOTAL';
TITLE 'FILES RECEIVED ON';
RUN;
i used print proc as follows,
PROC PRINT;
TITLE 'JOBNAME';
DATA _NULL_ ;
LENGTH JOBNAME $8 JOBNUMBR $8 JOBID $5;
TIOTPTR = PEEK(PEEK(540)+12);
JOBNAME = PEEKC(TIOTPTR,8);
PUT 'JOBNAME=' JOBNAME;
RUN;
But in the report, just the title is getting printed and not the jobname. the job name is displayed in SASLOG.
someone please help. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Use SYMPUT to output the values into macro variables; use &MACROVARIABLENAME to use in the title. Check the SAS web site if you haven't used SYMPUT and SYMGET before -- they're straightforward but not easily understood at first. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Following on from Robert ................
The only way that I have done something like this in the past is by using the macro variables in the title lines. Try it and see if it helps you.
Code: |
DATA _NULL_;
ABC = DATE();
BCD = PUT(ABC,DATE9.);
CALL SYMPUT ('DEF',BCD);
DATA OUT01;
AAA = 1; OUTPUT;
AAA = 2; OUTPUT;
AAA = 3; OUTPUT;
AAA = 4; OUTPUT;
AAA = 5; OUTPUT;
PROC PRINT DATA=OUT01 NOOBS;
TITLE1 'CREATE BY ME ON' &DEF ;
|
|
|
Back to top |
|
|
pranavaraj
New User
Joined: 03 Jan 2007 Posts: 15 Location: US
|
|
|
|
Thanks soooo much...
I tried what expat has suggested and it worked fine |
|
Back to top |
|
|
pranavaraj
New User
Joined: 03 Jan 2007 Posts: 15 Location: US
|
|
|
|
Hi Expat,
Instead of using PRINT proc, i displayed the jobname and number using FOOTNOTE in TABULATE proc itself. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
That's another option. I was pointing at using the TITLE line in TABULATE. The PROC PRINT was only an example |
|
Back to top |
|
|
|