Assigning Permanent Labels and Formats

Common Tasks and Their Corresponding Statements

You saw how to temporarily assign labels and formats within a PROC step in Creating List Reports. These temporary labels and formats are applicable only for the duration of the step. To permanently assign labels and formats, you use LABEL and FORMAT statements in DATA steps.
Note: Labels and formats do not affect how data is stored in the data set, but only how it appears in output.
Task
Statement to Use
Reference a SAS data library
Reference an external file
libname clinic 'c:usersmaydata'; 
filename tests 'c:users	mill.dat';
Name a SAS data set
Identify an external file
Describe raw data
data clinic.stress;
   infile tests obs=10; 
   input ID $ 1-4 Name $ 6-25 ...;
Subset data
if resthr<70 then delete;
if tolerance='D';
Drop unwanted variables
drop timemin timesec;
Create or modify a variable
TotalTime=(timemin*60)+timesec;
Initialize and retain variable
retain SumSec 5400;
Accumulate values
sumsec+totaltime;
Specify a variable's length
length TestLength $ 6;
Execute statements conditionally
if totaltime>800 then TestLength='Long'; 
else if 750<=totaltime<=800
     then TestLength='Normal'; 
else if totaltime<750
     then TestLength='Short';
Label a variable
label sumsec='Cumulative Total Seconds (+5,400)';
Format a variable
format sumsec comma6.;
Execute the DATA step
run;
List the data
proc print data=clinic.stress label;
Execute the final program step
run; 

Example: COMMA6. Format

To specify the label Cumulative Total Seconds (+5,400) and the format COMMA6. for the variable SumSec, you can submit the following program:
data clinic.stress; 
   infile tests; 
   input ID $ 1-4 Name $ 6-25 RestHR 27-29 MaxHR 31-33
         RecHR 35-37 TimeMin 39-40 TimeSec 42-43
         Tolerance $ 45; 
   if resthr<70 then delete; 
   if tolerance='D'; 
   drop timemin timesec; 
   TotalTime=(timemin*60)+timesec; 
   retain SumSec 5400; 
   sumsec+totaltime; 
   length TestLength $ 6; 
   if totaltime>800 then testlength='Long'; 
   else if 750<=totaltime<=800 then testlength='Normal'; 
   else if totaltime<750 then TestLength='Short'; 
   label sumsec='Cumulative Total Seconds (+5,400)'; 
   format sumsec comma6.; 
run;
When the new data set is displayed, SumSec is labeled and formatted as specified.
proc print data=clinic.stress label;
run;
Figure 11.5 Completed Clinic.Stress Data Set
Completed Clinic.Stress Data Set
Tip
Most SAS procedures automatically use permanent labels and formats in output, without requiring additional statements or options. If you assign temporary labels or formats within a PROC step, they override any permanent labels or formats that were assigned during the DATA step.
Last updated: January 10, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.196.244