Examples use generated data (datalines) or SASHELP, with fictitious data created for cases requiring external files to ensure the autonomy of the examples.
1 Code Block
DATA STEP, PROC PRINT
Explanation : This example reads a SAS data set from the sashelp library and writes the output to the SAS Work library. The SET statement reads the sashelp.shoes data set into the DATA step where it is processed by the WHERE statement. The WHERE statement selects only observations with a value greater than 500,000 for the sales variable. The DATA step then writes the output to the data set specified in the DATA statement (work.shoes).
Copied!
data work.shoes;
set sashelp.shoes;
where sales>500000;
run;
proc print data=shoes; run;
1
DATA work.shoes;
2
SET sashelp.shoes;
3
where sales>500000;
4
RUN;
5
PROC PRINTDATA=shoes; RUN;
2 Code Block
DATA STEP, PROC PRINT Data
Explanation : You can create data for a SAS data set by generating observations with programming statements rather than by reading data. A DATA step that reads no input goes through a single iteration. Detailed call explanations are: 1. Start the DATA step and create a SAS data set 'Investment'. 2. Calculate a value based on a capital investment of $2,000 and 7% interest each year from 1990 to 2009. Calculate variable values for one observation per DO loop iteration. 3. Write each observation to the Investment data set. 4. Write a note to the SAS log proving that the DATA step iterates only once. 5. Execute the DATA step. 6. To see your output, print the Investment data set with the PRINT procedure. 7. Use the FORMAT statement to write numeric values with dollar signs, commas, and decimals. 8. Execute the PRINT procedure.
Copied!
data investment;
begin='01JAN1990'd;
end='31DEC2009'd;
do year=year(begin) to year(end);
Capital+2000 + .07*(Capital+2000);
output;
end;
put 'The number of DATA step iterations is '_n_;
run;
proc print data=investment;
format Capital dollar12.2;
run;
1
DATA investment;
2
begin='01JAN1990'd;
3
END='31DEC2009'd;
4
DO year=year(begin) to year(END);
5
Capital+2000 + .07*(Capital+2000);
6
OUTPUT;
7
END;
8
put 'The number of DATA step iterations is '_n_;
9
RUN;
10
11
PROC PRINTDATA=investment;
12
FORMAT Capital dollar12.2;
13
RUN;
3 Code Block
DATA STEP, PROC PRINT
Explanation : This example reads three data sets from the Sashelp library and then concatenates them into a single output data set named concat. Since no SAS library or output location is specified, the output data set, concat, is temporarily saved in the SAS Work library. The output data set consists of observations from all three data sets. The order in which the data sets are concatenated into the output data set is based on how the data sets are listed in the SET statement. Observations from sashelp.nvst1 are first, followed by observations from sashelp.nvst2, followed by observations from sashelp.nvst3.
Copied!
data concat;
set sashelp.nvst1 sashelp.nvst2 sashelp.nvst3;
run;
proc print data=concat; run;
1
DATA concat;
2
SET sashelp.nvst1 sashelp.nvst2 sashelp.nvst3;
3
RUN;
4
PROC PRINTDATA=concat; RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.