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;
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
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
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.