IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Write output is SAS


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
phani.mf2011

New User


Joined: 15 Apr 2011
Posts: 17
Location: india

PostPosted: Wed Jul 27, 2011 4:51 pm
Reply with quote

Hi all I am very new to SAS and trying to learn on my own

Hi below is the code.I am trying to write output .The job is successful with MAXCC=0 but the output file is empty.

Please guide where I went wrong

Code:

//CGNLCOPY EXEC SAS                                             
//CUS      DD   DSN=CGNLST.PK.EZY.SAMP1,DISP=SHR                 
//TES      DD   DSN=CGNLST.PK.SAS.OUT1,DISP=(NEW,CATLG,DELETE), 
//             UNIT=DISK,LRECL=30,AVGREC=K,MGMTCLAS=MONTHLY,     
//             DATACLAS=DATAV,STORCLAS=STANDARD,                 
//             SPACE=(CYL,(10,10),RLSE)                         
//SYSIN    DD  *                                                 
  DATA DATA1;                                                   
  INFILE CUS;                                                   
  INPUT @ 1 EMNAME  $10. @ 11 GEN $1.                           
        @ 12 CITY   $10.;                                       
  RUN;                                                           
  DATA TES;                                                     
    SET DATA1;                                                   
    PUT @23 'SIVA' @;                                           
    OUTPUT;                                                     
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Wed Jul 27, 2011 4:53 pm
Reply with quote

Try (before the RUN;) :

IF 1 = 1;

or

OUTPUT;
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1744
Location: Tirupur, India

PostPosted: Wed Jul 27, 2011 5:00 pm
Reply with quote

Hello,
TES DD name is considered as a libname stetement in SAS(in this scenario or filename in some other references)
DATA TES; would create dataset in WORK library which is cleared off when the job completes, so you are getting empty output.
So change
Code:
DATA TES;

to
Code:
DATA TES.TES;


Use PROC PRINT;RUN; statements after datasteps to checkout the data you have read. Provided you have only limited amount of data, cos you dont want to go on printing 1000's of lines on spool.
If you could explain little more on what you are trying to do, then we could help you more on it.

Hope it helps.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1744
Location: Tirupur, India

PostPosted: Wed Jul 27, 2011 5:13 pm
Reply with quote

I don't know if this is optimal, but I always use the below allocation DCB cards for creating a SAS dataset,

Code:
//          DCB=(BLKSIZE=27648,LRECL=27648,RECFM=FS,DSORG=PS)


If you are intending to write RAW readable output into TES DD name then,
Change,
Code:
DATA TES;                                                     
    SET DATA1;                                                   
    PUT @23 'SIVA' @;                                           
    OUTPUT;   


to
Code:

DATA TES;                                                     
    SET DATA1;         
    FILE TES;                                         
    PUT @23 'SIVA' @;                                           
    OUTPUT;   
RUN;
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Jul 27, 2011 5:35 pm
Reply with quote

Are you attempting to create a SAS data base or are you attempting to write a sequential file? The two are quite different and are used in very different ways.

For a SAS data base, you must use a two-level DATA name to give the DDname and the SAS data base name such as:
Code:
  DATA DATA1;                                                   
  INFILE CUS;                                                   
  INPUT @ 1 EMNAME  $10. @ 11 GEN $1.                           
        @ 12 CITY   $10.;                                       
  RUN;                                                           
  DATA TES.XYZ;                                                     
    SET DATA1;                                                   
    PUT @23 'SIVA' @;                                           
For a sequential file, you must use a FILE statement instead of DATA statement:
Code:
  DATA DATA1;                                                   
  INFILE CUS;                                                   
  INPUT @ 1 EMNAME  $10. @ 11 GEN $1.                           
        @ 12 CITY   $10.;                                       
  RUN;                                                           
  DATA _NULL_;
    SET DATA1;                                                   
    FILE TES ;
    PUT @23 'SIVA' @;                                           
but be aware that this code will create a sequential file with nothing but the characters 'SIVA' starting in column 23 of each record. If you want the input data value in the output file, you must change your PUT statement to write them as well.

If you're building a sequential file with one additional data field, this code would be better:
Code:
  DATA DATA1;                                                   
  INFILE CUS;                                                   
  INPUT @ 1 EMNAME  $10. @ 11 GEN $1.                           
        @ 12 CITY   $10.;                                       
    FILE DATA1;                                                   
    PUT @ 1 EMNAME  $10. @ 11 GEN $1.                           
        @ 12 CITY   $10. @23 'SIVA' @;                                           
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1744
Location: Tirupur, India

PostPosted: Wed Jul 27, 2011 5:41 pm
Reply with quote

@Robert - Explained like a true expert professor or ex-expert professor (:
Back to top
View user's profile Send private message
phani.mf2011

New User


Joined: 15 Apr 2011
Posts: 17
Location: india

PostPosted: Wed Jul 27, 2011 6:17 pm
Reply with quote

Thanks a lot all

@ Robert---I am able to write data in output file.But it is happening for single records.How to do for all records in input file.Any looping possible
Back to top
View user's profile Send private message
phani.mf2011

New User


Joined: 15 Apr 2011
Posts: 17
Location: india

PostPosted: Wed Jul 27, 2011 6:23 pm
Reply with quote

Thanks a lot all

@ Robert---I am able to write data in output file.But it is happening for single records.How to do for all records in input file.Any looping possible
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Jul 27, 2011 6:24 pm
Reply with quote

The SAS data set does an implied loop -- SAS starts with the first line of the DATA step and goes through each line until the end of it, reading records and writing data as you specified. Unless you change the flow, SAS will then go back and read the next record and proceed through the data step again, and again, until end of data is reached. The last code I posted, with DATA ... INFILE ... INPUT ... FILE .. PUT is the standard way in SAS to completely process the input file and create a new output file.

Be aware that OUTPUT, for example, which you use liberally in your original posted code, can have side effects and is not typically required in a SAS data step since the data will be output by default to the DATA set whenever the end of the data step is reached. Take the last code I posted and try it -- you should get an output file with one record per input file record, exactly the same for the first 22 columns and with SIVA is added in columns 23 to 26.
Back to top
View user's profile Send private message
phani.mf2011

New User


Joined: 15 Apr 2011
Posts: 17
Location: india

PostPosted: Wed Jul 27, 2011 6:33 pm
Reply with quote

please find my code
Code:

//CGNLCOPY EXEC SAS                                             
//CUS      DD   DSN=CGNLST.PK.EZY.SAMP1,DISP=SHR               
//TES      DD   DSN=CGNLST.PK.SAS.OUT1,DISP=(NEW,CATLG,DELETE),
//             UNIT=DISK,LRECL=30,AVGREC=K,MGMTCLAS=MONTHLY,   
//             DATACLAS=DATAV,STORCLAS=STANDARD,               
//             SPACE=(CYL,(10,10),RLSE)                         
//SYSIN    DD  *                                               
  DATA DATA1;                                                   
  INFILE CUS;                                                   
  INPUT @ 1 EMNAME  $10. @ 11 GEN $1.                           
        @ 12 CITY   $10.;                                       
  DATA _NULL_;                                                 
    SET DATA1;                                                 
    FILE TES;                                                   
    PUT @1 EMNAME $10. @11 GEN $1.                             
        @12 CITY $10.                                           
        @23 'SIVA' @;                                           
Back to top
View user's profile Send private message
phani.mf2011

New User


Joined: 15 Apr 2011
Posts: 17
Location: india

PostPosted: Wed Jul 27, 2011 6:48 pm
Reply with quote

Please find my input and output file
input file
Code:
*****************************
 PHANI     1BANGALORE  00000100
 KRISHNA   1HYDERABAD  00000200
 VIJAYA    2TANUKU     00000300
 KAMAL     1BANGALORE  00000400
 RAVIPATI  1VISHAKAPATA00000500
 ****************************


Output file

Code:
***************************
RAVIPATI  1VISHAKAPAT SIVA
***************************
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Wed Jul 27, 2011 6:54 pm
Reply with quote

Change
Code:
   @23 'SIVA' @;
to
Code:
   @23 'SIVA' ;
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 27, 2011 6:56 pm
Reply with quote

Did you try Robert's suggested code?

Is "VISHAKAPATA" losing the final A some sort of typo, or lost in the code?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Jul 27, 2011 6:57 pm
Reply with quote

Well, SAS did EXACTLY what you told it to do -- and I missed it when I posted my code.

The trailing @ on the PUT staement is an error -- take it off. The trailing @ is usually used on an INPUT statement and tells SAS to retain the input record as you're going to read from it again. Since it is on a PUT statement, SAS retains the output record and overlays the data each time, so only the last input record actually gets written to the file. Without the trailing @, the code will write each record.

Sorry about that. icon_redface.gif
Back to top
View user's profile Send private message
phani.mf2011

New User


Joined: 15 Apr 2011
Posts: 17
Location: india

PostPosted: Wed Jul 27, 2011 7:05 pm
Reply with quote

Thanks a lot @expat and @Robert Sample

It work fine.Now I will try practice more
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Wed Jul 27, 2011 9:42 pm
Reply with quote

Robert, I'll PM you my bank account details for your payment icon_lol.gif icon_lol.gif icon_lol.gif
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Wed Jul 27, 2011 10:33 pm
Reply with quote

expat, I don't know if I can afford you! icon_biggrin.gif icon_biggrin.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8796
Location: Welsh Wales

PostPosted: Wed Jul 27, 2011 10:46 pm
Reply with quote

Exactly the same response as Mrs E icon_lol.gif
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 27, 2011 11:13 pm
Reply with quote

Robert, you could consider what we call a "part exchange" and I believe you would call a "trade in" :-) If it has at least four wheels*, he can "knock it out", I'm sure.

* including steering-wheel
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Thu Jul 28, 2011 12:02 am
Reply with quote

Quote:
If it has at least four wheels*,
I wonder if these four wheels have to be connected .... icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts REXX/CMS How to place command console... CLIST & REXX 4
No new posts batch SFTP job using AOPBATCH unable ... All Other Mainframe Topics 7
No new posts Reroute print output via REXX/SDSF TSO/ISPF 6
No new posts Concatenate 2 input datasets and give... JCL & VSAM 2
No new posts How to turn off 'ACTION' SDSF output ... TSO/ISPF 2
Search our Forums:

Back to Top