View previous topic :: View next topic
|
Author |
Message |
phani.mf2011
New User
Joined: 15 Apr 2011 Posts: 17 Location: india
|
|
|
|
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 |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Try (before the RUN;) :
IF 1 = 1;
or
OUTPUT; |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1744 Location: Tirupur, India
|
|
|
|
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
to
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 |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1744 Location: Tirupur, India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1744 Location: Tirupur, India
|
|
|
|
@Robert - Explained like a true expert professor or ex-expert professor (: |
|
Back to top |
|
|
phani.mf2011
New User
Joined: 15 Apr 2011 Posts: 17 Location: india
|
|
|
|
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 |
|
|
phani.mf2011
New User
Joined: 15 Apr 2011 Posts: 17 Location: india
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
phani.mf2011
New User
Joined: 15 Apr 2011 Posts: 17 Location: india
|
|
|
|
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 |
|
|
phani.mf2011
New User
Joined: 15 Apr 2011 Posts: 17 Location: india
|
|
|
|
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 |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Change
to
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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. |
|
Back to top |
|
|
phani.mf2011
New User
Joined: 15 Apr 2011 Posts: 17 Location: india
|
|
|
|
Thanks a lot @expat and @Robert Sample
It work fine.Now I will try practice more |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Robert, I'll PM you my bank account details for your payment |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
expat, I don't know if I can afford you! |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8796 Location: Welsh Wales
|
|
|
|
Exactly the same response as Mrs E |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
If it has at least four wheels*, |
I wonder if these four wheels have to be connected .... |
|
Back to top |
|
|
|