I was able to show all of the values except for the Total Sales column. I can show the value in thousands, but the values in hundred just won't show up. How do I fix the code? Thanks. Attached png file is the output of the code.
data bikes1;
infile "/folders/myfolders/austin.txt" dlm='09'x;
;
length
Country $14
Bike $13
Model $10
Units 4
Price 6
TotalSales 7
;
format Price dollar6. TotalSales dollar7.;
input Country Bike Model Units Price dollar6. TotalSales dollar9.;
run;
proc print data=bikes1 noobs;
run;
*
USA Road Bike Trek 5000 $2,200 $11,000
USA Hybrid Trek 4500 $650 $2,925
USA Road Bike Cannondale 2000 $2,100 $4,200
USA Mountain Bike Trek 6000 $1,200 $7,200
USA Mountain Bike Cannondale 4000 $2,700 $10,800
United Kingdom Hybrid Cannondale 500 $880 $440
United Kingdom Hybrid Trek 800 $490 $392
United Kingdom Road Bike Cannondale 1200 $2,123 $2,548
United Kingdom Road Bike Trek 2444 $2,100 $5,132
United Kingdom Mountain Bike Trek 1211 $1,121 $1,358
Italy Mountain Bike Trek 3400 $1,877 $6,382
Italy Road Bike Trek 4500 $2,890 $13,005
Italy Hybrid Trek 700 $690 $483
France Road Bike Cannondale 900 $3,700 $3,330
France Road Bike Trek 3400 $2,500 $8,500
France Hybrid Trek 1100 $540 $594
France Mountain Bike Cannondale 800 $1,899 $1,519
France Mountain Bike Trek 5600 $1,300 $7,280
;
data bikes1;
infile "/folders/myfolders/austin.txt" dlm='09'x;
;
length
Country $14
Bike $13
Model $10
Units 4
Price 6
TotalSales 7
;
informat Price dollar6. TotalSales dollar7.;
input Country Bike Model Units Price TotalSales ;
run;
proc print data=bikes1 noobs;
run;
Made two changes
1. format changed to informat
2. input statement I removed all the format.
There are various things wrong with the read in. This code will read in the data correctly:
data bikes1; infile datalines dlm="|"; length country $14 bike $13 model $10 units 4 price 6 totalsales 7; format price dollar6. totalSales dollar9.; informat price dollar6. totalsales dollar9.; input country bike model units price totalsales; datalines; USA|Mountain Bike|Cannondale|4000|$2,700|$10,800 United Kingdom|Hybrid|Cannondale|500|$880|$440 ; run;
hello,
you shall check the import step and look at the log.
if your data is organised well in the *.txt file the import shall work.
by the way better use modified list input rather than length statement.
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000144370.htm
data bikes1;
infile "/folders/myfolders/austin.txt" dlm='09'x;
;
length
Country $14
Bike $13
Model $10
Units 4
Price 6
TotalSales 7
;
informat Price dollar6. TotalSales dollar7.;
input Country Bike Model Units Price TotalSales ;
run;
proc print data=bikes1 noobs;
run;
Made two changes
1. format changed to informat
2. input statement I removed all the format.
Thanks a lot. Then, I added another line of code to put the $ format back in.
data bikes1;
infile "/folders/myfolders/austin.txt" dlm='09'x;
;
length
Country $14
Bike $13
Model $10
Units 4
Price 6
TotalSales 7
;
informat Price dollar6. TotalSales dollar7.;
format Price dollar6. TotalSales dollar7.;
input Country Bike Model Units Price TotalSales;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.