Help using Base SAS procedures

proc import error

Reply
Contributor
Posts: 56

proc import error

Hi All,

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.

182  Range="not$A5Smiley Very Happy10";

     -----

     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

183  run;

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

Thanks

Shiva

Frequent Contributor
Posts: 117

Re: proc import error

Posted in reply to shivakrishna

Try this:

PROC IMPORT OUT=cla

            DATAFILE= "C:\shiva\not.csv"

            DBMS=CSV REPLACE;

     SHEET="sheet 1";

     GETNAMES=YES;

     MIXED=YES;

     USEDATE=YES;

     SCANTIME=YES;

RUN;

Contributor
Posts: 56

Re: proc import error

thank you vomer

but i need to capture only part of the data (A5Smiley Very Happy10)no need full data.

thanks

Shiva

Respected Advisor
Posts: 3,799

Re: proc import error

Posted in reply to shivakrishna

SHEET and RANGE have no meaning when DBMS is CSV.

Contributor
Posts: 56

Re: proc import error

Posted in reply to data_null__

why ?

Occasional Contributor
Posts: 9

Re: proc import error

Posted in reply to shivakrishna

Range is applicable for Excel files not for Comma Separated Value files.

Excel file:

PROC IMPORT OUT= WORK.TEST

            DATAFILE= "C:\test.xls"

            DBMS=EXCEL2000 REPLACE;

     RANGE="A4Smiley Very Happy5";

     GETNAMES=NO;

RUN;

CSV file :

proc import datafile="C:\temp\test.csv"

     out=shoes

     dbms=csv

     replace;

     getnames=no;

run;

Super User
Posts: 19,768

Re: proc import error

Posted in reply to shivakrishna

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.

Frequent Contributor
Posts: 117

Re: proc import error

Posted in reply to shivakrishna

Try this:

PROC IMPORT DATAFILE="c:\<path>\test.xls"

  OUT=seq(<for dataset options - see below> )

  DBMS=excel REPLACE;

  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.

Contributor
Posts: 56

Re: proc import error

Hi All

May i know we cannot read part of the data from the CSV file. if yes WHY ?

Thanks

Shiva

Regular Contributor
Posts: 195

Re: proc import error

Posted in reply to shivakrishna

Hello,

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...

%macro csv_extract(start,end);

/* Design data structure as per your requirement */

data csv_data;

   infile "C:\Documents and Settings\ShahUr01\Urvish\test.csv" dlm = "," firstobs = 2;  

   input name $ age;

run;

/* Extract the required data once it is available in SAS */

data csv_sample;

   set csv_data;

   if _n_ GE &start. and _n_ LE &end.;

run;

%mend;

%csv_extract(5,10);

-Urvish

Contributor
Posts: 56

Re: proc import error

Posted in reply to UrvishShah

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)

Shiva

Frequent Contributor
Posts: 137

Re: proc import error

Posted in reply to shivakrishna

Hi,

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.

Thanks,

Charlotte

Occasional Contributor
Posts: 9

Re: proc import error

Posted in reply to shivakrishna

WHY DO WE GIVE RANGE TO READ CSV FILES USING PROC IMPORT? IT IS UNNECESSARY ONE.


Contributor
Posts: 56

Re: proc import error

Posted in reply to antony_allianz

thank you antony,

can you please elaborate why it is unnesessary..

shiva


Occasional Contributor
Posts: 9

Re: proc import error

Posted in reply to shivakrishna

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.

Ask a Question
Discussion stats
  • 18 replies
  • 4428 views
  • 6 likes
  • 10 in conversation