Unformatted text preview: ariable. Then you can change the value of the macro variable in the %LET statement, and SAS will repeat the new value throughout your program. The general form a %LET statement is %LET macro-variable-name = value; where macro-variable-name is a name you make up following the standard rules for SAS names (32 characters or fewer in length; starting with a letter or underscore; and containing only letters, numerals, or underscores). Value is the text to be substituted for the macro variable name, and can be up to 64,000 characters long. The following statements each create a macro variable. %LET iterations = 5; %LET winner = Lance Armstrong; Notice that there are no quotation marks around value even when it contains characters. Blanks at the beginning and end will be trimmed, and everything else between the equal sign and semicolon will become part of the value for the macro variable. To use the macro variable, you simply add the ampersand prefix (&) and stick the macro variable name wherever you want its value to be substituted. DO i = 1 to &iterations; TITLE "First: &winner"; After being resolved by the macro processor, these statements would become DO i = 1 to 5; TITLE "First: Lance Armstrong"; Example A company that manufactures bicycles maintains a file listing all their models. For each model they record its name, class (Road, Track, or Mountain), list price, and frame material. Here is a subset of the data: Black Bora Delta Breeze Jet Stream Mistral Nor'easter Santa Ana Scirocco Trade Wind Track 796 Aluminum Road 399 CroMoly Track 1130 CroMoly Road 1995 Carbon Comp Mountain 899 Aluminum Mountain 459 Aluminum Mountain 2256 Titanium Road 759 Aluminum 2 SUGI 29 Tutorials This DATA step reads the raw data from a file named Models.dat creating a SAS data set named MODELS. DATA models; INFILE 'c:\MyRawData\Models.dat' TRUNCOVER; INPUT Model $ 1-12 Class $ Price Frame $ 28-38; RUN; Frequently the sales people want a list showing all the models of one particular class. Sometimes they want a list of road bikes, but other time...
View Full Document
This note was uploaded on 03/21/2013 for the course AMS 597 taught by Professor Xing during the Spring '11 term at SUNY Stony Brook.
- Spring '11