DATA Step, Macro, Functions and more

format and print new values

Reply
Occasional Contributor
Posts: 17

format and print new values

Hi, guys

I'm struggling in print my new value (Mileage, Cost), but unfortunately it still did not work even I used commax and dollarx.

The result is (.), and I'm not sure what I'm missing. I use sas university edition.

Need help

data usedcar;
infile "/folders/myshortcuts/SASUniversityEdition/module 3/usedcars.txt"
firstobs=2 expandtabs obs=50 dsd
;
input
Year $2. Manufacturer $16. Model $16. Mileage commax. cost dollarx.
;
proc
contents data = usedcar varnum;
Proc
Format;
value Mileage low - 50000 = '<50,000'
50000 - high = '>=50,000'
other = 'Unknown';

Value Cost low - 5000 = 'Economic'
5000-10000 = 'Moderate'
other = 'Expensive';
Proc
print;
run;

 Here is my log

 
 
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
61
62 data usedcar;
63 infile "/folders/myshortcuts/SASUniversityEdition/module 3/usedcars.txt"
64 firstobs=2 expandtabs obs=50 dsd
65 ;
66 input
67 Year $2. Manufacturer $16. Model $16. Mileage commax. cost dollarx.
68 ;
 
NOTE: The infile "/folders/myshortcuts/SASUniversityEdition/module 3/usedcars.txt" is:
(no system-specific pathname available),
(no system-specific file attributes available)
 
NOTE: 49 records were read from the infile "/folders/myshortcuts/SASUniversityEdition/module 3/usedcars.txt".
The minimum record length was 91.
The maximum record length was 91.
NOTE: The data set WORK.USEDCAR has 49 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.02 seconds
 
69 proc
70 contents data = usedcar varnum;
 
 
NOTE: PROCEDURE CONTENTS used (Total process time):
real time 0.51 seconds
cpu time 0.46 seconds
 
71 Proc
72 Format;
 
73 value Mileage low - 50000 = '<50,000'
74 50000 - high = '>=50,000'
75 other = 'Unknown';
NOTE: Format MILEAGE is already on the library WORK.FORMATS.
NOTE: Format MILEAGE has been output.
76
77 Value Cost low - 5000 = 'Economic'
78 5000-10000 = 'Moderate'
79 other = 'Expensive';
NOTE: Format COST is already on the library WORK.FORMATS.
NOTE: Format COST has been output.
 
NOTE: PROCEDURE FORMAT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
 
80 Proc
81 print;
 
82 run;
 
NOTE: There were 49 observations read from the data set WORK.USEDCAR.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.50 seconds
cpu time 0.49 seconds
 
82 !
 
83
84
85 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
98
 
xxxxxxxxxxxxxxxxx Here is my data (Example) xxxxxxxxxxxxxxxxx

94 Chrysler LeBaron 50,000 $7,999 
PROC Star
Posts: 1,558

Re: format and print new values

You have defined the format but not used it.

You can for example add a format statement to the proc print.

PROC Star
Posts: 7,356

Re: format and print new values

Your first datastep won't run as expected, Some of your infile options are throwing off the results and some of your informats are wrong. I think that you'll find the following to work a lot better:

data usedcar;
 infile "/folders/myshortcuts/SASUniversityEdition/module 3/usedcars.txt"
    firstobs=2 obs=50 ;
 informat year $2.;
 informat Manufacturer $16.;
 informat Model $16.;
 informat Mileage comma10.;
 informat cost dollar7.;
 input Year Manufacturer Model  Mileage cost;
run;

Art, CEO, AnalystFinder.com

 

Ask a Question
Discussion stats
  • 2 replies
  • 96 views
  • 0 likes
  • 3 in conversation