SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Formatting Variable Values
Assigning Formats to Variables


Remember, you can assign formats in both DATA and PROC steps. Here, the COMMA8.2 format is permanently associated with RoomCharge in the DATA step and the DOLLAR6. format is temporarily associated with RoomCharge in the PROC step.

     data perm.aprbills;
	infile aprdata;
        input LastName $8. @10 DateIn mmddyy8. 
              +1 DateOut mmddyy8.
              +1 RoomRate 6. @35 EquipCost 6.;
        Days=dateout-datein+1;
        RoomCharge=days*roomrate;
        Total=roomcharge+equipcost;
        format datein dateout date9. roomrate 6.2 
               roomcharge comma8.2 total dollar9.2;
     run;
        proc print data=perm.aprbills;
           format roomcharge dollar6.;
     run;
The format assigned in the PROC PRINT step overrides the permanent format only in the output generated by this procedure.


Obs LastName DateIn DateOut RoomRate EquipCost Days RoomCharge Total
1 Akron 05APR1990 09APR1990 175.00 298.45 4 $700 $998.45
2 Brown 12APR1990 01MAY1990 125.00 326.78 19 $2,375 $2,701.78
3 Carnes 27APR1990 29APR1990 125.00 174.24 2 $250 $424.24
4 Denison 11APR1990 12APR1990 175.00 87.41 1 $175 $262.41


However, the COMMA8.2 format is still permanently associated with the variable RoomCharge.


Column Properties for SAS Data Set Perm.Aprbills
Column Name Type Length Format
LastName Text
8
DateIn Number
8
DATE9.
DateOut Number
8
DATE9.
RoomRate Number
8
6.2
EquipCost Number
8
Days Number
8
RoomCharge Number
8
COMMA8.2
Total Number
8
DOLLAR9.2


If you submit another procedure without a FORMAT statement, the values are displayed with the formats assigned in the DATA step.
     proc print data=perm.aprbills;
        var lastname datein dateout roomrate
            days roomcharge equipcost total;
     run;

Obs LastName DateIn DateOut RoomRate Days RoomCharge EquipCost Total
1 Akron 05APR1990 09APR1990 175.00 4 700.00 298.45 $998.45
2 Brown 12APR1990 01MAY1990 125.00 19 2,375.00 326.78 $2,701.78
3 Carnes 27APR1990 29APR1990 125.00 2 250.00 174.24 $424.24
4 Denison 11APR1990 12APR1990 175.00 1 175.00 87.41 $262.41
5 Fields 15APR1990 22APR1990 175.00 7 1,225.00 378.96 $1,603.96
6 Jaminson 16APR1990 23APR1990 125.00 7 875.00 346.28 $1,221.28



back||next


Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement