160 likes | 343 Views
SYMply PUT: GET the most out of SYMPUTX and SYMGETN. SYMply PUT: GET the most out of SYMPUTX and SYMGETN. Robert Howard Veridical Solutions San Diego, CA. ©2011, Veridical Solutions.
E N D
SYMply PUT: GET the most out of SYMPUTX and SYMGETN SYMply PUT: GET the most out of SYMPUTX and SYMGETN Robert Howard Veridical Solutions San Diego, CA ©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://www.veridicalsolutions.com info@veridicalsolutions.com
SYMply PUT: GET the most out of SYMPUTX and SYMGETN Presentation Outline • Call SYMPUTX routine • SYMGETN and SYMGET functions • PUT it all together: A Practical Example ©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://www.veridicalsolutions.com info@veridicalsolutions.com
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://www.veridicalsolutions.com info@veridicalsolutions.com
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://www.veridicalsolutions.com info@veridicalsolutions.com
SYMply PUT: GET the most out of SYMPUTX and SYMGETN The CALL SYMPUTX Routine Example 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://www.veridicalsolutions.com info@veridicalsolutions.com
SYMply PUT: GET the most out of SYMPUTX and SYMGETN The CALL SYMPUTX Routine Example 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 DSET1 ©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://www.veridicalsolutions.com info@veridicalsolutions.com
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://www.veridicalsolutions.com info@veridicalsolutions.com
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://www.veridicalsolutions.com info@veridicalsolutions.com
SYMply PUT: GET the most out of SYMPUTX and SYMGETN SYMGET and SYMGETN functions Example 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://www.veridicalsolutions.com info@veridicalsolutions.com
SYMply PUT: GET the most out of SYMPUTX and SYMGETN SYMGET and SYMGETN functions DSET4 Example 4: DSET3 data dset4; set dset3; age=symgetn(name); run; 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://www.veridicalsolutions.com info@veridicalsolutions.com
SYMply PUT: GET the most out of SYMPUTX and SYMGETN PUT it all together: A Practical Example DSET5 Calculate the number and percentages of subjects by gender for each treatment group. First obtain number of subjects in each Treatment Group. proc freq data=dset5 noprint; tables treat/out=trtfreq; run; TRTFREQ ©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://www.veridicalsolutions.com info@veridicalsolutions.com
SYMply PUT: GET the most out of SYMPUTX and SYMGETN PUT it all together: A Practical Example TRTFREQ Using the CALL SYMPUTX routine, we assign macro variables for the value of TREAT data _null_; set trtfreq; call symputx(treat,count); run; 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://www.veridicalsolutions.com info@veridicalsolutions.com
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://www.veridicalsolutions.com info@veridicalsolutions.com
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 data final; set freq0; percent=put(count/symgetn(treat),percent7.1); run; FINAL ©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://www.veridicalsolutions.com info@veridicalsolutions.com
SYMply PUT: GET the most out of SYMPUTX and SYMGETN In Conclusion The CALL SYMPUTX routine and SYMGETN and SYMGET functions are: • simple, yet powerful tools • efficient and effective method to store and retrieve • macro variables • use together to save time and keep program dynamic ©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://www.veridicalsolutions.com info@veridicalsolutions.com
SYMply PUT: GET the most out of SYMPUTX and SYMGETN Thank you for your time and interest! Rob Howard Veridical Solutions P.O. Box 656 Del Mar, CA 92014 rob.howard@veridicalsolutions.com www.veridicalsolutions.com ©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://www.veridicalsolutions.com info@veridicalsolutions.com