BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
atulsingh
Obsidian | Level 7

I am importing the attached dataset using the INFILE statement. But the 'quantity' 'sales' and 'profit' variables have missing values against them, Please have a look.

 

data inf_globalsale;
infile'/folders/myfolders/global_sale.csv'
LRECL=60000 DLM=',' FIRSTOBS=2;
informat Order_ID$32. Order_Date ddmmyy10. Ship_Date ddmmyy10. Customer_ID$32. Segment$32. Country$32. Category$32. Sales dollar10.2;
format Order_Date ddmmyy10. Ship_Date ddmmyy10. Sales dollar10.2;
input Order_ID$ Order_Date Ship_Date Customer_ID$ Segment$ City$ State$ Country$ Category$ Sales Quantity Discount Profit;
run;

proc print data=inf_globalsale;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

One you probably want to use the DSD option to properly handle missing values.  Also both PROFIT and SALES need to use the COMMA (or DOLLAR) informat to handle the dollar signs and commas that appear in the data.

Also do NOT include a decimal specification on a INFORMAT unless you know that the decimal points do NOT appear in the text strings and need to be added to get the proper magnitude of the numbers.

 

data inf_globalsale;
  infile "&path/global_sale.csv" dsd firstobs=2  ;
  length Order_ID $32 Order_Date Ship_Date 8 
         Customer_ID Segment City $32 State $8 Country $32 
         Category $32 Sales Quantity Discount Profit 8
  ;
  informat Order_Date Ship_Date ddmmyy. Sales Profit dollar.;
  format Order_Date Ship_Date yymmdd10. ;
  input Order_ID -- Profit;
run;

Let's print some of the values to see if it worked.

proc print data=&syslast(obs=5);
 var Order_Date Sales--Profit ;
run;

Result.

Obs    Order_Date     Sales     Quantity    Discount     Profit

  1    2014-11-11     221.98        2          0.0        62.15
  2    2014-02-05    3709.40        9          0.1      -288.77
  3    2014-10-17    5175.17        9          0.1       919.97
  4    2014-01-28    2892.51        5          0.1       -96.54
  5    2014-11-05    2832.96        8          0.0       311.52

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

One you probably want to use the DSD option to properly handle missing values.  Also both PROFIT and SALES need to use the COMMA (or DOLLAR) informat to handle the dollar signs and commas that appear in the data.

Also do NOT include a decimal specification on a INFORMAT unless you know that the decimal points do NOT appear in the text strings and need to be added to get the proper magnitude of the numbers.

 

data inf_globalsale;
  infile "&path/global_sale.csv" dsd firstobs=2  ;
  length Order_ID $32 Order_Date Ship_Date 8 
         Customer_ID Segment City $32 State $8 Country $32 
         Category $32 Sales Quantity Discount Profit 8
  ;
  informat Order_Date Ship_Date ddmmyy. Sales Profit dollar.;
  format Order_Date Ship_Date yymmdd10. ;
  input Order_ID -- Profit;
run;

Let's print some of the values to see if it worked.

proc print data=&syslast(obs=5);
 var Order_Date Sales--Profit ;
run;

Result.

Obs    Order_Date     Sales     Quantity    Discount     Profit

  1    2014-11-11     221.98        2          0.0        62.15
  2    2014-02-05    3709.40        9          0.1      -288.77
  3    2014-10-17    5175.17        9          0.1       919.97
  4    2014-01-28    2892.51        5          0.1       -96.54
  5    2014-11-05    2832.96        8          0.0       311.52

 

art297
Opal | Level 21

An alternative but good to know solution is to let SAS do the work for you and, if needed, modify the resulting code. e.g.:

 

proc import datafile='/folders/myfolders/global_sale.csv' out=inf_globalsale dbms=csv replace;
run;

 

In the present case three additional variables will be imported, as you have a stray character in one of the non-used columns after your data.

 

Art, CEO, AnalystFinder.com

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 1669 views
  • 2 likes
  • 3 in conversation