06-20-2013 01:50 PM
i am getting error while importing the data from csv (proc import)
181 proc import out= cla datafile ="C:\shiva\not.csv" dbms=csv replace;
NOTE: The previous statement has been deleted.
ERROR 180-322: Statement is not valid or it is used out of proper order.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
07-04-2013 08:33 AM
Range is applicable for Excel files not for Comma Separated Value files.
PROC IMPORT OUT= WORK.TEST
CSV file :
proc import datafile="C:\temp\test.csv"
07-04-2013 10:47 AM
CSV files are comma separated variables text flat files. There are no cells and the data structure is that it is separated by commas and has a delimiter to specify the end of line.
RANGE, as specified, is a construct of Excel. Excel knows how to read CSV files, and CSV files usually automatically open in Excel but it is not an excel file and the ranges have no meaning in CSV files. If you want to use RANGE, convert it to an .xls or .xlsx file explicitly.
If your table or information has header information or some other columns you don't want, you'll need to find another way to explicitly read it, using a data step most likely.
06-20-2013 11:00 PM
PROC IMPORT DATAFILE="c:\<path>\test.xls"
OUT=seq(<for dataset options - see below> )
GETNAMES=yes; * variable names are in row 1 ;
RANGE="< range-name OR absolute-range"; * omit if you want to read the entire worksheet;
Of course, you will need to save the file in xls instead of csv.
07-03-2013 08:24 AM
Here is my try...You can read any feild of data by using OBS options...i think data step works fine rather than proc import...
It will be better if you post your CSV sample file...Here i made simple macro based on your need which extract the 5 to 10 observations...But you need to fix the variable structure in your INPUT statement...
/* Design data structure as per your requirement */
infile "C:\Documents and Settings\ShahUr01\Urvish\test.csv" dlm = "," firstobs = 2;
input name $ age;
/* Extract the required data once it is available in SAS */
if _n_ GE &start. and _n_ LE &end.;
07-03-2013 08:29 AM
Hi urvish thank you for your code but i know by using datastep....
can you please why we are not create part of the data of csv file by using proc step (proc import)
07-03-2013 09:24 AM
Your question gave me an opportunity to research and learn something new. Anyway, if you are looking to import only selected columns from an external file using PROC IMPORT, it seems the RANGE option in specifying the selected columns only works for .xls files alone and not for CSV files. I guess I am probably reiterating the point DN made earlier, however it helps in my understanding as i am a newbie too.
For CSV files, ideally it is best to read using datastep and to be honest in my production work environment the best practice is actually to avoid proc import. Of course, saying that you would want to do what suits you best.
Nevertheless if you do find something works to specify the range in CSV, please post that solution, so we can all learn.
07-04-2013 12:52 AM
IF WE WANT PARTICULAR ROWS WE USE FIRST OBS & OBS.
IF WE WANT PARTICULAR ROWS IN RUN TIME USING MACROS WITH PARAMETERS & USING INFILE WITH IN MACRO DEFINITION.