©2011, veridical solutions. sas and all other sas institute inc. product or service names are...
TRANSCRIPT
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
Robert HowardVeridical Solutions
San Diego, CA
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
• Call SYMPUTX routine
• SYMGETN and SYMGET functions
• PUT it all together: A Practical Example
Presentation Outline
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
The CALL SYMPUTX Routine
• Used in the DATA step
• Stores values into macro variables
• Once stored, these values can be accessed globally throughout a program
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
The CALL SYMPUTX Routine• Syntax: call symputx(macro-variable,value);
• The macro-variable argument can be: a) A character string in quotation marks b) A character variable name
•The value argument can be: a) A character or numeric value b) A character or numeric variable name
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
The CALL SYMPUTX RoutineExample 1:data _null_; call symputx(‘thisyear’,2011); call symputx(‘trt0’,‘Placebo’);run;
%put &thisyear &trt0;
The log result displays: 2011 Placebo
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
The CALL SYMPUTX RoutineExample 2: data _null_;
set dset1; call symputx(name,age);run;
%put &chaz &mac &ellie &savannah &jillian &alex &ayden &quinn;
The log result displays: 14 13 8 5 5 5 4 3
©2011, Veridical Solutions. 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
DSET1
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
SYMGET and SYMGETN functions
• Also used in the DATA step
• Retrieves values of previously stored macro variables and assigns these values in programmer-defined variables
• SYMGET is used to retrieve character values
• SYMGETN is used to retrieve numeric values
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
SYMGET and SYMGETN functions• Syntax for SYMGET: <variable>=symget(‘macro-variable’);• Syntax for SYMGETN: <variable>=symgetn(‘macro-variable’);
• The macro-variable argument can be: a) The name of a macro-variable with no ampersand (within single quotes) b) The name of a variable with values that have been assigned as macro variables (no quotes)
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
SYMGET and SYMGETN functionsExample 3:Recall previous example where &thisyear has a stored value of 2011.Since &thisyear is numeric, we will use SYMGETN
data dset2; year=symgetn(‘thisyear’);run;
DSET2
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
SYMGET and SYMGETN functionsExample 4:
data dset4; set dset3; age=symgetn(name);run;
DSET3
DSET4
DSET4 is created with a new variable, AGE, which contains the corresponding values associated with each instance of NAME.
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
PUT it all together: A Practical ExampleDSET5 Calculate the number and percentages
of subjects by gender for each treatment group.
proc freq data=dset5 noprint; tables treat / out=trtfreq;run;
TRTFREQ
First obtain number of subjects in each Treatment Group.
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
PUT it all together: A Practical Example
Using the CALL SYMPUTX routine, we assign macro variables for the value of TREAT
data _null_; set trtfreq; call symputx(treat,count);run;
TRTFREQ
The macro variables &A and &B are assigned with values 8 and 3, respectively.
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
PUT it all together: A Practical Example
Now we’ll obtain the number of “Male” and “Female” subjects by Treatment Group.
proc freq data=dset5 noprint; tables treat*gender / out=freq0;run;
FREQ0
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
PUT it all together: A Practical Example
We’ll use the SYMGETN function to calculate the percentages
FINAL
data final; set freq0; percent=put(count/symgetn(treat),percent7.1);run;
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
• simple, yet powerful tools
• efficient and effective method to store and retrieve macro variables
• use together to save time and keep program dynamic
In Conclusion
The CALL SYMPUTX routine andSYMGETN and SYMGET functions are:
©2011, Veridical Solutions. 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
http://[email protected]
SYMply PUT: GET the most out of SYMPUTX and SYMGETN
Rob HowardVeridical Solutions
P.O. Box 656Del Mar, CA 92014
Thank you for your time and interest!
©2011, Veridical Solutions. 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