BookmarkSubscribeRSS Feed
jhapankaj
Calcite | Level 5

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.
6 REPLIES 6
Tom
Super User Tom
Super User

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 ;
art297
Opal | Level 21

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

 

jhapankaj
Calcite | Level 5

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

Tom
Super User Tom
Super User

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;

 

art297
Opal | Level 21

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

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 9289 views
  • 0 likes
  • 4 in conversation