Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SAS INPUT STATEMENT

Status
Not open for further replies.

SPhill

Programmer
Sep 17, 2003
32
GB
I'm using version 6.09 mainframe SAS and recently had a request to read a CSV file type for testing in SAS. Has anyone got any 'INPUT' statements that would work on this version for a dataset which contains comma seperated values?
My input @ statments for fixed width datasets can't be used on this but I believe there is a quick input command for CSV type files in SAS, but not sure whether our version supports it?

Thanks

Scott
 
Try this.
*** SET A FILE REF ***;

filename temp "c:\data.csv"; *** insert the file that you want;

data data1;
infile temp dlm = ',' MISSOVER DSD lrecl=32767;
*** SET YOUR INPUTS BY COLUMN THE DOLLAR SIGN***;
*** DENOTES THAT THE VAR IS A CHAR VAR ***;
input name $
balance
comment $;
*** YOU MAY SET INFORMATS AND FORMATS HERE ***;
format name $25 balance 8.2 comment $200;
*informat name $25 balance 8.2 etc......;

***IF YOUR VAR NAMES ARE ON THE TOP ROW**;
***YOU NEED TO SKIP THAT ROW. **;

if _n_ ge 2 then
output;
run;

I hope this helps you.
klaz
 
Thanks Klaz, I've been trying something like this before, but I'm still getting errors, like 'variable name contains more than 8 characters', even if I try and format it after the input statement. The only other way I can do this (which is a pain) is by importing the file into the mainframe environment as fix'd width and then setting the attributes using the infile statement, i.e.
INFILE BGVAL1;
INPUT @1 POLNO £ 9
@10 TERR IB2.
@12 PRE £ 4.
etc etc;
I know there is a way of doing CSV files using PC sas but I'm using JCL in TSO in a mainframe environment, (6.09 mainframe SAS) and can't get this to work.
-------------------------------------------------------

DATA TEST;
INFILE sasdata DLM = ',' MISSOVER DSD;
INPUT SPCODE POL_NUMBER;
RUN;

e.g of dataset:
!,SPCODE,POL_NUMBER,INRREF,etc,
*, 1, 93000016, 1,etc,



 
SPhill,
The error you get seems to be a SAS issue not a mainfarme issue. I couldn't help but notice that your input statement had a variable name with more than 8 letters. The 8 letter limit is a SAS limit across all platforms until version 7 SAS. Perhaps the code that I gave you will work with a shorter var name.
I hope this helps you.
Klaz2002
 
Thanks again Klaz, I've just had another go at this and got it to work, it was the length of the var names I was using that was causing the prob. I was trying to keep them the same as contained within the dataset. Using FIRSTOBS2 and renaming the VARs to less than 8 charas has cured it. A bit more work than I had hoped but it's all up and running now.

Cheers

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top