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

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
;

 

 


bike.png
1 ACCEPTED SOLUTION

Accepted Solutions
RahulG
Barite | Level 11
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.

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Loko
Barite | Level 11

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

RahulG
Barite | Level 11
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.

jermanie
Fluorite | Level 6

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 782 views
  • 1 like
  • 4 in conversation