DATA Step, Macro, Functions and more

No observations in data set

Reply
New Contributor
Posts: 2

No observations in data set

Hi,

 

I am getting the following message:

NOTE: No observations in data set PANKAJ.CAR_SALES.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.01 seconds
cpu time 0.00 seconds
 
This is the code i wrote:
libname Pankaj '/folders/myfolders/Pankaj';
filename carsales '/folders/myfolders/Pankaj/Car sales.csv';
run;
data Pankaj.car_sales;
infile carsales dlm=',' missover dsd;
input manufacturer: $10.
model: $10.
sales: 4.3.;


proc print data=Pankaj.car_sales (obs=5);
run;
 
The file is located on my desktop under myfolder/pankaj and it is named Car sales and in csv format. Please help? Also, attached is the file. Thanks.
Super User
Posts: 10,623

Re: No observations in data set

Posted in reply to jhapankaj

The NOTEs are from the proc print, which is irrelevant here. Please post the log of the data step that reads the csv.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 8,289

Re: No observations in data set

Posted in reply to jhapankaj

You have multiple mistakes with the INPUT statement.

The critical one is a syntactical mistake is you have two periods in the last informat specification.  

562   data car_sales;
563     infile carsales dlm=',' missover dsd;
564     input manufacturer: $10. model: $10. sales: 4.3.;
                                                       -
                                                       22
                                                       200
ERROR 22-322: Syntax error, expecting one of the following: a name, arrayname, #, (, +, -, /, //, ;, @, @@.

ERROR 200-322: The symbol is not recognized and will be ignored.

565   run;

You also should not have the decimal part on an INFORMAT. For an INFORMAT that means that SAS should assume that there is an implied decimal point when there is no decimal point in the text being read.  So if you read '1234' using 4.3 informat then the result is the number 1.234 and not the 1234.

You do not need to provide any informat for SAS to understand how to read a number, especially when you are using list mode to read from a delimited file where there is no need to tell SAS how many characters to read. 

input manufacturer :$10. model :$10. sales ;
Super User
Posts: 8,220

Re: No observations in data set

Posted in reply to jhapankaj

Three things to add to what @Tom said. You don't need a run statement after a filename statement. You should get into the practice of adding a run statement to end all datasteps. Your data contains a header record, thus you have to include a firstobs option to skip that record. e.g.:

 

libname Pankaj '/folders/myfolders/Pankaj';
filename carsales '/folders/myfolders/Pankaj/Car sales.csv';
data Pankaj.car_sales;
  infile carsales dlm=',' firstobs=2 missover dsd;
  input manufacturer: $10.
        model: $10.
        sales
        ;
run;

proc print data=Pankaj.car_sales (obs=5);
run;

Art, CEO, AnalystFinder.com

 

New Contributor
Posts: 2

Re: No observations in data set

Thank you everyone!!! I will include these details in my programming.

Super User
Super User
Posts: 8,289

Re: No observations in data set

Posted in reply to jhapankaj

Personally I would just take the first line from the text file.

Manufacturer,Model,Sales ,4-year resale value,Vehicle type,Price in thousands,Engine size,Horsepower,Wheelbase,Width,Length,Curb weight,Fuel capacity,Fuel efficiency,Latest Launch

Copy it into the SAS editor and convert it to a LENGTH statement to define the variables.  Some of the values will need to be changed to be valid SAS names. (Replace/remove spaces, start with letter or underscore, not too long for humans to type)

  length Manufacturer $15 Model $15 Sales 8 Resale4yr 8 
         Vehicle_type $20 PriceK 8 Engine_size 8
         Horsepower 8 Wheelbase 8 Width 8 Length 8 Curb_weight 8
         Fuel_capacity 8 Fuel_efficiency 8 Latest_Launch 8
  ;

Only the date value needs to have an informat for SAS to know how to read it.  Also the date value is the only one that needs a format attached so that its value will display in human readable format.

data car_sales;
  infile carsales dlm=',' truncover dsd firstobs=2 ;
  length Manufacturer $15 Model $15 Sales 8 Resale4yr 8 
         Vehicle_type $20 PriceK 8 Engine_size 8
         Horsepower 8 Wheelbase 8 Width 8 Length 8 Curb_weight 8
         Fuel_capacity 8 Fuel_efficiency 8 Latest_Launch 8
  ;
  informat Latest_Launch date.;
  format Latest_Launch yymmdd10. ;
  input Manufacturer -- Latest_Launch ;
run;

 

Super User
Posts: 8,220

Re: No observations in data set

Like @Tom said, we all have our personal preferences. Mine, in this case, would be to run proc import. i.e.:

proc import datafile='/folders/myfolders/Pankaj/Car sales.csv'
            out=have
            dbms=csv
            replace
  ;
run;

Doesn't always work perfectly, but does all of the grunt work and provides code that one can modify and, if necessary, re-run.

 

Art, CEO, AnalystFinder.com

 

Ask a Question
Discussion stats
  • 6 replies
  • 260 views
  • 0 likes
  • 4 in conversation