%SYSFUNC( BRIDGE TO EXTERNAL DATA

Size: px
Start display at page:

Download "%SYSFUNC( BRIDGE TO EXTERNAL DATA"

Transcription

1 %SYSFUNC( BRIDGE TO EXTERNAL DATA ) Hsiwei Yu (Michael), Northrop Grumman, Washington, D.C. ABSTRACT %SYSFUNC, a macro function introduced in SAS Version 6.11 and 6.09E, enables Base SAS functions to be called inside macro environment, thereby greatly enhances the power of SAS macro language. This study attempts to explore %SYSFUNC usage in retrieving data set and external file information via Base functions such as OPEN, FETCH, GETVARN, etc. Finally, %SYSFUNC applications arising from SAS/Graph and SQL are presented. INTRODUCTION %SYSFUNC is documented in SAS Macro Language: Reference, 1 st edition, 1997, with limited illustrations on its potential capability. Yindra (1998) showed using %SYSFUNC to access external file and directory information. He mentioned %SYSFUNC can read records from SAS data set, but no SAS programs were given. Yu (1998) gave outline about using %SYSFUNC to read data set and external file, but short of complete example. Imagine this assignment: For every character variable in a SAS data set, run Proc Freq; for numeric variable, run Proc Univariate; output from each variable s run must be saved to a separate external file; perform this standard analysis on every data set in any given data library. Central to this assignment is obtaining SAS data library and data set information, then generate the required language elements, i.e. Proc Univariate or Freq. Prior to %SYSFUNC, only Data Step can access external data; a Data Step generating dynamic code for later execution could have Macro or Base language elements all mixed in, at various resolution time, in double or single quotes, making it hard on the developer to concentrate on the program logic at hand. Using %SYSFUNC, external data is available in macro environment, and dynamic program generation via macro programming becomes easier. %SYSFUNC can access three sources of external data of interest to macro programmer, i.e. SAS data sets, external files, and directory entries (or members). %SYSFUNC syntax: %SYSFUNC( SAS_function( arguments ) <, format>); where SAS_function can also be a function written with SAS/Toolkit. Arguments can be a macro variable or text expression. If the returned value contains special character or mnemonic operators, such as %, &, AND, EQ, then use %QSYSFUNC to mask these characters. Format is optional and applies to specified SAS format to returned value. Data Step function returns 200 characters at most. A sample call: title %SYSFUNC( date(), weekdate18. ) Absence Report ; SAMPLE 1: READ A DATA SET %Read_Dat can be used as a basis for solving the aforementioned assignment. It deciphers variable information and generates Proc Freq or Univariate accordingly. These Base functions allow the reading of both data set descriptor and actual records. However, we can t write to SAS data set via %SYSFUNC in macro environment. OPEN opens a SAS data set CLOSE closes SAS data set ATTRC returns character value on the requested attribute of a SAS data set, such as SORTEDBY ATTRN returns numeric value on the requested attribute of a SAS data set, such as NOBS, ANOBS, ANY, and NVARS VARNUM returns the number of a data set variable. This number is used later by GETVARC and GETVARN VARTYPE returns the data type of a data set variable FETCH reads the next nondeleted record from data set into Data Set Data Vector (DSDV) FETCHOBS reads a specified record from data set GETVARC returns character variable s value GETVARN returns numeric variable s value MACRO TO READ A DATA SET %macro Read_Dat( dsn=, where= ); %if &where ne %then %do; %let dsn= &dsn(where=(&where)); %let dsid= %sysfunc(open(&dsn,is)); %if &dsid = 0 %then %do; %put Can%str(% )t open DSN=&dsn; %goto quit_bye; %let n_obs= %sysfunc( ATTRN( &dsid, nobs )); %put Current DSN=&dsn has &n_obs records;

2 %let N_Name= %sysfunc( VARNUM( &dsid, NAME )); %let N_Type= %sysfunc( VARNUM( &dsid, TYPE )); %do %while ( %sysfunc( FETCH( &dsid )) ne -1 ); %let NAME= %sysfunc( GETVARC( &dsid, &N_Name )); %let TYPE= %sysfunc( GETVARC( &dsid, &N_Type )); %if &TYPE = char %then %do; Proc Freq data= sasuser.houses; Tables &NAME; %else %do; Proc Univariate data= sasuser.houses; Var &NAME; %quit_bye: %let rc= %sysfunc( CLOSE( &dsid )); %mend Read_Dat; %Read_Dat( dsn= sashelp.vcolumn, where= %str( libname = SASUSER and memname = HOUSES )); Several Notes Since %SYSFUNC is a macro function, it is not necessary to enclose character values in quotes. Given a variable name as input, VARNUM returns its corresponding number. GETVARC and GETVARN use this number as input to return the variable s value. SAS view returns 1 as number of observations. With where clause in effect, it s simpler to use FETCH and test the return code value of 1 for end-of-file. Or, %let I= 1; %do %while ( %sysfunc( FETECHOBS( &dsid, &I )) = 0 ); %let I= %eval( &I + 1 );.. A data set opened in macro environment can still be read by other Proc, such as Print, it just cannot be updated. COMPARE WITH ALTERNATIVES Prior to %SYSFUNC, if we have to read a SAS data set and generate programs based on records in the data set, one solution could be: data _null_; file pgm_based_on_current_record.sas ; set sashelp.vcolumn( where = ( libname = SASUSER and memname = HOUSES )); if type = num then put '/* Run Proc Univariate */'; else put '/* Run Proc Freq */'; /* watch out UN-balanced quotes! */ %Include 'pgm_based_on_current_record.sas'; OR use Call Execute( ); such as data _null_; set sashelp.vcolumn( where = ( libname = SASUSER and memname = HOUSES )); if type = num then call execute( Proc Univariate data= asuser.houses; var name ; ); else call execute( Proc Freq data= sasuser.houses; tables name ; ); With Data Step approach, an external file must be written and later %Include d. For both the Data Step and Call Execute, the programmer must be careful with quotes. It could be cumbersome at times to count the single and double quotes. Comparing with Call Execute, remember if Call Execute produces macro language elements, they are executed immediately; if Call Execute produces SAS language elements, they are executed after the end of the current Data Step. With %SYSFUNC, since it is invoked in macro environment, timing is straightforward. Finally, macro program based on %SYSFUNC should be easier to read and comprehend. SAMPLE 2: READ AND WRITE EXTERNAL FILE %Write_Fi can be adapted to read a data set, and write to external file. %Read_Fil can be changed to read an external file of different record layout. Here's the sample data file; Street is 16 characters, Style 8, and Price varying length. Each field is separated by a space.

3 Sheppard Avenue RANCH Rand Street SPLIT 6 Market Street CONDO Garris Street TWOSTORY 10 FOPEN opens an external file FCLOSE closes a file, directory, or directory member FGET copies data from the File Data Buffer (FDB) FPUT moves data to the FDB starting at the current column position FWRITE writes a record to external file FREAD reads a record from external file into FDB FRLEN returns the size of the last record read, or the current record size for a file opened for output FPOS sets the position of the column pointer in the FDB MACROS TO READ AND WRITE EXTERNAL FILE %macro Write_Fi( out_fref=, in_dsn=); %let fid= %sysfunc( FOPEN( &out_fref, o )); %let dsid= %sysfunc(open(&in_dsn)); %let N_Street= %sysfunc( VARNUM( &dsid, street )); %let N_Style= %sysfunc( VARNUM( &dsid, style )); %let N_Price= %sysfunc( VARNUM( &dsid, price )); %let i= 1; %do %while ( %sysfunc( FETCH( &dsid )) = 0 ); %let Street= %sysfunc( GETVARC( &dsid, &N_Street )); %let Style= %sysfunc( GETVARC( &dsid, &N_Style )); %let Price= %sysfunc( GETVARN( &dsid, &N_Price )); %if %sysfunc( MOD( &i, 2 ), 1. ) = 0 %then %let Price= %sysfunc( INT( &Price / )); ; %let i= %eval( &i + 1 ); %let rc= %sysfunc( FPUT( &fid, &Street )); %let rc= %sysfunc( FPOS( &fid, 18 )); %let rc= %sysfunc( FPUT( &fid, &Style )); %let rc= %sysfunc( FPOS( &fid, 27 )); %let rc= %sysfunc( FPUT( &fid, &Price )); %let rc= %sysfunc( FWRITE( &fid )); %let rc= %sysfunc( FCLOSE( &fid )); %let rc= %sysfunc( CLOSE( &dsid )); %mend Write_Fi; %macro Read_Fil( in_fref= ); %let fid=%sysfunc(fopen(&in_fref,i)); %do %while ( %sysfunc( FREAD( &fid )) eq 0 ); %let rc= %sysfunc( FGET( &fid, STREET, 16 )); %let street= %sysfunc( TRIM( &street )); %let rc= %sysfunc( FPOS( &fid, 18 )); %let rc= %sysfunc( FGET( &fid, STYLE, 8 )); %let style= %sysfunc( TRIM( &style )); %let rc= %sysfunc( FPOS( &fid, 27 )); %* Compute the number of bytes occupied by PRICE; %let fld_len= %eval( %sysfunc( FRLEN( &fid )) - 26 ); %let rc= %sysfunc( FGET( &fid, PRICE, &fld_len )); %put Street=&STREET Style=&STYLE Price=&PRICE; %* Do something based on these current values; %let rc= %sysfunc( fclose( &fid )); %mend Read_Fil; filename data@txt data@txt unit=sysda space=(trk,(5,5)) recfm= fb lrecl= 80 blksize= 8000; %Write_Fi( out_fref= data@txt, in_dsn=sasuser.houses ); %Read_Fil( in_fref= data@txt ); Several Notes Fput simply prepares data in the FDB, it is Fwrite that finally outputs the FDB to the external file. %sysfunc( function( arguments(s)) <, format>); accepts optional format argument and

4 applies it to the functional result. By default, numeric result has format of BEST12. %sysfunc( FGET( &fid, STYLE, 8 )); then a macro variable, &STYLE, is automatically created and filled with its value. Fpos and Fget together are like using column position input in a Data Step. Fget function for reading text files are no substitutes for a Data Step. This example simply shows it can be done. SAMPLE 3: READ DIRECTORY ENTRIES %Dir_Read shows Base functions to retrieve directory and file attribute information. It reads a directory on Unix, Windows, or partition data set (PDS) on MVS. This macro reads all members of a directory then successively opens each file and writes out its contents. DOPEN opens a directory MOPEN opens a directory member file DINFO returns attribute value for a directory DOPTNAME returns a specified directory attribute DOPTNUM returns the number of attributes available to a directory FINFO returns a specified information item for a file FOPTNAME returns the name of an information item for a file FOPTNUM returns the number of attributes available to a file DNUM returns the number of members in a directory DREAD returns the name of a directory member MACRO TO READ DIRECTORY %macro Dir_Read( in_fref= ); %let dir_id= %sysfunc( DOPEN( &in_fref )); %let num_item= %sysfunc( DOPTNUM( &dir_id )); %put Info available on directory:; %do i= 1 %to &num_item; %let attr_nam= %sysfunc( DOPTNAME( &dir_id, &i )); %let attr_val= %sysfunc( DINFO( &dir_id, &attr_nam )); %put I=&i Attr_Name= &attr_nam Attr_Value=&attr_val; %let dnum= %sysfunc(dnum(&dir_id)); %do i= 1 %to &dnum; %* For each member, open and read; %let name= %sysfunc( DREAD( &dir_id, &i )); %put I=&i Memeber_name= &name; %let file_id= %sysfunc( MOPEN( &dir_id, &name )); %let finfo_nm= %sysfunc( FOPTNUM( &file_id )); %do j= 1 %do &finfo_nm; %let fin_nam= %sysfunc( FOPTNAME( &file_id, &j )); %let fin_valu= %sysfunc( FINFO( &file_id, &fin_nam )); %do %while ( %sysfunc( FREAD( &file_id )) = 0 ); %let rc= %sysfunc( FGET( &file_id, my_str, 200 )); %put %superq(my_str); %let rc= %sysfunc( FCLOSE( &file_id )); %let dsid=%sysfunc(dclose(&dir_id)); %mend Dir_Read; filename a.jcl.cntl disp=shr; * filename a d:\sas-programs ; %Dir_Read( in_fref= a ); Note With minor adjustment, it runs on UNIX, PC, and MVS. SAS Macro Language: Reference has a list of portable SAS language functions for %SYSFUNC. PROBLEM 1, DESCRIPTION We wish to show a bar chart representing sites with particular types of location information. Because region covers several states, state covers several counties, and so on, it is only natural to request that the bar representing region should be at the leftmost, and bars toward the right be progressively more geographically restrictive than that on the left. Here s the sample data Region Code State Post Code County Code Zip Code City Name Street Address Lat/Long

5 However, SAS/Graph defaults to alphabetical ordering for discrete bars. See Figure 1 for a simple Proc Gchart output, and Figure 2 for the desired graph. We need to tell Proc Gchart to use data set s original record sequence, without hard-coding. PROBLEM 1, SOLUTION * Data Step generating annotate statements not shown; %macro Midpnts; %let dsid= %sysfunc( OPEN( work.p1vb1, is )); %let nobs= %sysfunc( ATTRN( &dsid, nobs )); %let N_Id= %sysfunc( VARNUM( &dsid, id )); %do i= 1 %to &nobs; %let rc=%sysfunc(fetch(&dsid)); /* The next statement will be seen by Proc Gchart s midpoints= option */ "%sysfunc( TRIM( %sysfunc( GETVARC( &dsid, &N_Id ))))" %let dsid= %sysfunc(close(&dsid)); %mend Midpnts; %macro Values; %let dsid= %sysfunc( OPEN( work.p1vb1, is )); %let nobs= %sysfunc( ATTRN( &dsid, nobs )); %let var_num= %sysfunc( VARNUM( &dsid, id )); /* SAS language elements to be seen by Axis1 s value= option */ ( %do i= 1 %to &nobs; %let rc=%sysfunc(fetch(&dsid)); h= 1 a= 90 f= simplex "%sysfunc( TRIM( %sysfunc( GETVARC( &dsid, &var_num ))))" ) /* End of Axis1 s value= */ %let dsid= %sysfunc(close(&dsid)); %mend Values; pattern1 color= g value= Solid; * Other pattern statements not shown; axis1 value= %Values label= ( h= 1 f= simplex 'Type of Information' ); proc gchart data= p1vb1 annotate= anno; vbar id / sumvar= pct type= sum patternid= midpoint midpoints= %Midpnts quit; maxis= axis1; Discussions This data set was opened three times, first by macro generating midpoints= in Proc Gchart, second by macro generating value= in Axis1, and finally Proc Gchart reads it for graphing. We could have used a Data Step and written to two external files (one for use by midpoints= and one for value=), then the data set will be read only twice. It is a trade-off between execution efficiency and programming simplicity. %SYSFUNC can have nested Base functions calls, %sysfunc(trim(%sysfunc(getvarc( )))); Depending on context, the returned value can be directly used as Base language elements without first assigned to a macro variable. PROBLEM 2, DESCRIPTION Occasionally when I m beginning to analyze a new data set, I like to have a global view of the key variables distinctiveness. For example, sasuser.fitness has 3 distinct Group values, 14 distinct Age values, and 20 distinct values when combining Age and Group. The following SQL is the basic building block: proc sql; select count( distinct age ), count( distinct group ), count( distinct put( age, 8. ) put( group, 8. )) from sasuser.fitness; Since the concatenation operator,, is only applicable to character operands, numeric values are transformed by using the Put function. Also note each key variable is referenced twice by SQL, first in count distinct by itself, and second time in count distinct of all the key combinations. PROBLEM 2, SOLUTION Macro %T_uniq (shown in Appendix 1) is developed to take an arbitrary number of key variables and accumulate the result from a data set across multiple invocations. A sample run and output: %T_uniq( indata= sasuser.fitness, keys= age group, outdata= acum_fnl ); %T_uniq( indata= sasuser.houses, keys= style bedrooms street, outdata= acum_fnl ); proc print data= acum_fnl;

6 Dataset Attributes Values SASUSER.FITNESS TOTOBS 31 GROUP 3 AGE CTKEYS SASUSER.HOUSES TOTOBS STYLE 15 4 BEDROOMS 4 STREET CTKEYS The first half of %T_uniq is to break down the list of key variables, in &keys, into individual variable. The second half is to query sashelp.vcolumn view twice. The first read of sashelp.vcolumn is to count distinct on individual keys, and the second read is for concatenating together all the keys into a long, temporary, character variable for count distinct. The length of this variable can only be 200 characters. %sysfunc( REWIND( )) is used to reposition the column attributes view for the second read. Appendix 2 contains the equivalent by using Data Step writing to two external files. The sashelp.vcolumn view is read only once, but two macros are dynamically generated, with one being imbedded in the other. Though these two versions are about the same program length, I believe the Data Step alternative is less intuitive. That s why I decided to rewrite it using %SYSFUNC. SUMMARY %SYSFUNC macro function provides useful ways to bridge traditional Macro and Base language. It simplifies thing we had to do without it and offers more power to traditional macro programming. Make %SYSFUNC part of your tool set. For question and comments, or to obtain complete sample programs, please send to Hsiwei Yu (Michael) at vhyu@netkonnect.net or yu.michael@epa.gov Reference: SAS Institute Inc. (1997), SAS Macro Language: Reference, 1 st edition, Cary, NC: SAS Institute Inc. Chris Yindra (1998), %SYSFUNC The Brave New Macro World, Proceedings of the Twenty-third Annual SAS Users Group Internal Conference Michael Yu (1998), %SYSFUNC( A Bridge.. ); DC SAS Users Group Newsletter, 1 st quarter 1998 Ian Whitlock (1997), Call Execute: How and Why, Proceedings of the Twenty-second Annual SAS Users Group Internal Conference Robert Virgile (1997), Magic With Call Execute, Proceedings of the Twenty-second Annual SAS Users Group Internal Conference ACKNOWLEDGEMENTS Special thanks to Tom Lewis of Lockheed Martin and Huang Liang for review and constructive critique, helping me to clarify points I was trying to express. SAS, SAS/Graph, are registered trademarks of SAS Institute Inc. in the USA and other countries. APPENDIX 1: T_UNIQ.SAS MACRO /* t_uniq.sas << a macro program >> Uses %sysfunc( ), and does not use external file for generating SAS programs for later execution. */ %macro t_uniq( indata=, keys=, outdata= ); proc datasets lib= work nolist memtype= data; delete orig_dif result; quit; %let inlib= %scan( &indata, 1,. ); %let inmem= %scan( &indata, 2,. ); %if &inmem = %then %do; %let inmem= &inlib; %let inlib= work; %let inlib=%sysfunc(upcase(&inlib )); %let inmem=%sysfunc(upcase(&inmem )); %let keys= %sysfunc(upcase(&keys )); /* Watch out %nrstr(%x) for actually quoting, or blocking any special meaning, the x character, so that macro will treat the x character as simply text. */ %let whr= libname eq "&inlib" and memname eq "&inmem" and name in %nrstr(%(); %let iter= 1; %let t&iter= %scan( &keys, &iter, %str( )); %do %while( &&t&iter ne ); %let whr= &whr "&&t&iter"; %let iter= %eval( &iter + 1 );

7 %let t&iter= %scan( &keys, &iter, %str( )); /* Again watch out the use of %nrstr(%x). */ %let whr= &whr %nrstr(%)); %** put whr=&whr..; /* The final WHERE string */ /* SASHELP.VCOLUMN is a view; related to dictionary.columns */ %let dsid= %sysfunc( OPEN( sashelp.vcolumn( where= ( &whr )))); %** put dsid= &dsid..; %let fmt= %sysfunc( VARNUM( &dsid, format )); %let nam= %sysfunc( VARNUM( &dsid, name )); %let typ= %sysfunc( VARNUM( &dsid, type )); proc sql; create table orig_dif as select "&inlib..&inmem" as memname length= 17, &iter as nokeys, count( * ) as totobs %do %while ( %sysfunc( FETCH( &dsid )) ne -1 ); %let name= %sysfunc( GETVARC( &dsid, &nam )); SQL */ as &name /* Below is for the PROC, count( distinct &name ) /* REWIND even works on a VIEW! */ %let rc= %sysfunc( REWIND( &dsid ));, count( distinct %do %while ( %sysfunc( FETCH( &dsid )) ne -1 ); %let type= %sysfunc( GETVARC( &dsid, &typ )); %let format= %sysfunc( GETVARC( &dsid, &fmt )); %let name= %sysfunc( GETVARC( &dsid, &nam )); %if &type eq char %then %do; /* Below is for the PROC SQL. Character variable */ &name %else %do; %if &format eq %then %do; /* Below is for the PROC SQL. Numeric var without format */ put( &name, best18. ) %else %do; /* Below is for the PROC SQL. Numeric var with format */ put( &name, &format ) A ) as ctkeys /* Close the data set as soon as possible */ %let dsid= %sysfunc( CLOSE( &dsid )); from &inlib..&inmem; quit; /* End of the PROC SQL */ proc transpose data= orig_dif out= result; copy nokeys memname; proc append base= &outdata new= result; label col1= # of Values _name_= Attributes ; %mend t_uniq; Appendix 2: Data Step Alternative %let keys= %sysfunc(upcase(&keys)); %let indata= %sysfunc( UPCASE( &indata )); data key_vars; set sashelp.vcolumn; where trim( libname ) '.' trim( memname ) = "&indata"; where also ( name in ( %let iter= 1; %let t&iter= %scan( &keys, &iter, %str( )); %do %while( &&t&iter ne ); "&&t&iter" %let iter= %eval( &iter + 1 ); %let t&iter= %scan( &keys, &iter, %str( )); )); %let iter= %eval( &iter - 1 );

8 %let DIR= %sysfunc(pathname( work )); filename a "&DIR/temp-10.sas"; filename b "&DIR/temp-11.sas"; options ls= 72; data _null_; set key_vars end= EOF; if _n_ = 1 then do; file b new; put %macro b; count( distinct( ; file a new; put proc sql; / create table orig_dif as / select / " &indata as memname length= 17," / " &iter as nokeys," / count( * ) as totobs, / %b ; end; file a; put, count( distinct name ) as name; file b; if type = char then do; put name ; end; else do; put put( name +(-1), best18. ) ; end; if EOF then do; file b; put " " )) as ctkeys / %mend b; ; file a; put "from &indata;" / quit; ; end; %inc b; %inc a;

%SYSFUNC - The Brave New Macro World Chris Yindra, C. Y. Training Associates

%SYSFUNC - The Brave New Macro World Chris Yindra, C. Y. Training Associates %SYSFUNC - The Brave New Macro World Chris Yindra, C. Y. Training Associates ABSTRACT The new macro function %SYSFUNC (SAS rel 6.12) allows access by the macro processor to most data step functions and

More information

Building Intelligent Macros: Using Metadata Functions with the SAS Macro Language Arthur L. Carpenter California Occidental Consultants, Anchorage, AK

Building Intelligent Macros: Using Metadata Functions with the SAS Macro Language Arthur L. Carpenter California Occidental Consultants, Anchorage, AK Paper 835-2017 Building Intelligent Macros: Using Metadata Functions with the SAS Macro Language Arthur L. Carpenter California Occidental Consultants, Anchorage, AK ABSTRACT The SAS macro language gives

More information

Functions and CALL Routines

Functions and CALL Routines 179 CHAPTER 13 Functions and CALL Routines Functions and CALL Routines in the OS/390 Environment 179 Dictionary 180 DINFO 182 DOPEN 186 DOPTNAME 186 DOPTNUM 187 FCLOSE 188 FDELETE 188 FEXIST 189 FILEEXIST

More information

Uncommon Techniques for Common Variables

Uncommon Techniques for Common Variables Paper 11863-2016 Uncommon Techniques for Common Variables Christopher J. Bost, MDRC, New York, NY ABSTRACT If a variable occurs in more than one data set being merged, the last value (from the variable

More information

Introduction. Keeping Efficiency in Perspective. CHAPTER 11 Writing Efficient and Portable Macros

Introduction. Keeping Efficiency in Perspective. CHAPTER 11 Writing Efficient and Portable Macros 129 CHAPTER 11 Writing Efficient and Portable Macros Introduction 129 Keeping Efficiency in Perspective 129 Writing Efficient Macros 130 Use Macros Wisely 130 Use Name Style Macros 131 Avoid Nested Macro

More information

Contents of SAS Programming Techniques

Contents of SAS Programming Techniques Contents of SAS Programming Techniques Chapter 1 About SAS 1.1 Introduction 1.1.1 SAS modules 1.1.2 SAS module classification 1.1.3 SAS features 1.1.4 Three levels of SAS techniques 1.1.5 Chapter goal

More information

Get into the Groove with %SYSFUNC: Generalizing SAS Macros with Conditionally Executed Code

Get into the Groove with %SYSFUNC: Generalizing SAS Macros with Conditionally Executed Code Get into the Groove with %SYSFUNC: Generalizing SAS Macros with Conditionally Executed Code Kathy Hardis Fraeman, United BioSource Corporation, Bethesda, MD ABSTRACT %SYSFUNC was originally developed in

More information

Introduction. Getting Started with the Macro Facility CHAPTER 1

Introduction. Getting Started with the Macro Facility CHAPTER 1 1 CHAPTER 1 Introduction Getting Started with the Macro Facility 1 Replacing Text Strings Using Macro Variables 2 Generating SAS Code Using Macros 3 Inserting Comments in Macros 4 Macro Definition Containing

More information

SAS Macro Dynamics - From Simple Basics to Powerful Invocations Rick Andrews, Office of the Actuary, CMS, Baltimore, MD

SAS Macro Dynamics - From Simple Basics to Powerful Invocations Rick Andrews, Office of the Actuary, CMS, Baltimore, MD Paper BB-7 SAS Macro Dynamics - From Simple Basics to Powerful Invocations Rick Andrews, Office of the Actuary, CMS, Baltimore, MD ABSTRACT The SAS Macro Facility offers a mechanism for expanding and customizing

More information

Make Your Life a Little Easier: A Collection of SAS Macro Utilities. Pete Lund, Northwest Crime and Social Research, Olympia, WA

Make Your Life a Little Easier: A Collection of SAS Macro Utilities. Pete Lund, Northwest Crime and Social Research, Olympia, WA Make Your Life a Little Easier: A Collection of SAS Macro Utilities Pete Lund, Northwest Crime and Social Research, Olympia, WA ABSTRACT SAS Macros are used in a variety of ways: to automate the generation

More information

Submitting SAS Code On The Side

Submitting SAS Code On The Side ABSTRACT PharmaSUG 2013 - Paper AD24-SAS Submitting SAS Code On The Side Rick Langston, SAS Institute Inc., Cary NC This paper explains the new DOSUBL function and how it can submit SAS code to run "on

More information

Base and Advance SAS

Base and Advance SAS Base and Advance SAS BASE SAS INTRODUCTION An Overview of the SAS System SAS Tasks Output produced by the SAS System SAS Tools (SAS Program - Data step and Proc step) A sample SAS program Exploring SAS

More information

SAS Macro Language: Reference

SAS Macro Language: Reference SAS Macro Language: Reference INTRODUCTION Getting Started with the Macro Facility This is the macro facility language reference for the SAS System. It is a reference for the SAS macro language processor

More information

%MISSING: A SAS Macro to Report Missing Value Percentages for a Multi-Year Multi-File Information System

%MISSING: A SAS Macro to Report Missing Value Percentages for a Multi-Year Multi-File Information System %MISSING: A SAS Macro to Report Missing Value Percentages for a Multi-Year Multi-File Information System Rushi Patel, Creative Information Technology, Inc., Arlington, VA ABSTRACT It is common to find

More information

Your Own SAS Macros Are as Powerful as You Are Ingenious

Your Own SAS Macros Are as Powerful as You Are Ingenious Paper CC166 Your Own SAS Macros Are as Powerful as You Are Ingenious Yinghua Shi, Department Of Treasury, Washington, DC ABSTRACT This article proposes, for user-written SAS macros, separate definitions

More information

Macro Magic III. SNUG Presentation (30mins)

Macro Magic III. SNUG Presentation (30mins) Macro Magic III SNUG Presentation (30mins) Overview Macro Magic Posters have been displayed at the last 2 SUGA presentations. Continue the trend Hopefully everyone will learn something new SAS Macro -

More information

ABSTRACT. Paper CC-031

ABSTRACT. Paper CC-031 Paper CC-031 Using Functions SYSFUNC and IFC to Conditionally Execute Statements in Open Code Ronald J. Fehd, Centers for Disease Control and Prevention, Atlanta, GA, USA ABSTRACT Audience Keywords Information

More information

Sample Questions. SAS Advanced Programming for SAS 9. Question 1. Question 2

Sample Questions. SAS Advanced Programming for SAS 9. Question 1. Question 2 Sample Questions The following sample questions are not inclusive and do not necessarily represent all of the types of questions that comprise the exams. The questions are not designed to assess an individual's

More information

Arthur L. Carpenter California Occidental Consultants, Oceanside, California

Arthur L. Carpenter California Occidental Consultants, Oceanside, California Paper 028-30 Storing and Using a List of Values in a Macro Variable Arthur L. Carpenter California Occidental Consultants, Oceanside, California ABSTRACT When using the macro language it is not at all

More information

Using a Control Dataset to Manage Production Compiled Macro Library Curtis E. Reid, Bureau of Labor Statistics, Washington, DC

Using a Control Dataset to Manage Production Compiled Macro Library Curtis E. Reid, Bureau of Labor Statistics, Washington, DC AP06 Using a Control Dataset to Manage Production Compiled Macro Library Curtis E. Reid, Bureau of Labor Statistics, Washington, DC ABSTRACT By default, SAS compiles and stores all macros into the WORK

More information

SAS Data Integration Studio Take Control with Conditional & Looping Transformations

SAS Data Integration Studio Take Control with Conditional & Looping Transformations Paper 1179-2017 SAS Data Integration Studio Take Control with Conditional & Looping Transformations Harry Droogendyk, Stratia Consulting Inc. ABSTRACT SAS Data Integration Studio jobs are not always linear.

More information

Better Metadata Through SAS II: %SYSFUNC, PROC DATASETS, and Dictionary Tables

Better Metadata Through SAS II: %SYSFUNC, PROC DATASETS, and Dictionary Tables Paper 3458-2015 Better Metadata Through SAS II: %SYSFUNC, PROC DATASETS, and Dictionary Tables ABSTRACT Louise Hadden, Abt Associates Inc., Cambridge, MA SAS provides a wealth of resources for users to

More information

SAS Macro Dynamics: from Simple Basics to Powerful Invocations Rick Andrews, Office of Research, Development, and Information, Baltimore, MD

SAS Macro Dynamics: from Simple Basics to Powerful Invocations Rick Andrews, Office of Research, Development, and Information, Baltimore, MD ABSTRACT CODERS CORNER SAS Macro Dynamics: from Simple Basics to Powerful Invocations Rick Andrews, Office of Research, Development, and Information, Baltimore, MD The SAS Macro Facility offers a mechanism

More information

Foundations and Fundamentals. SAS System Options: The True Heroes of Macro Debugging Kevin Russell and Russ Tyndall, SAS Institute Inc.

Foundations and Fundamentals. SAS System Options: The True Heroes of Macro Debugging Kevin Russell and Russ Tyndall, SAS Institute Inc. SAS System Options: The True Heroes of Macro Debugging Kevin Russell and Russ Tyndall, SAS Institute Inc., Cary, NC ABSTRACT It is not uncommon for the first draft of any macro application to contain errors.

More information

Macro to compute best transform variable for the model

Macro to compute best transform variable for the model Paper 3103-2015 Macro to compute best transform variable for the model Nancy Hu, Discover Financial Service ABSTRACT This study is intended to assist Analysts to generate the best of variables using simple

More information

Developing Data-Driven SAS Programs Using Proc Contents

Developing Data-Driven SAS Programs Using Proc Contents Developing Data-Driven SAS Programs Using Proc Contents Robert W. Graebner, Quintiles, Inc., Kansas City, MO ABSTRACT It is often desirable to write SAS programs that adapt to different data set structures

More information

Efficient Processing of Long Lists of Variable Names

Efficient Processing of Long Lists of Variable Names Efficient Processing of Long Lists of Variable Names Paulette W. Staum, Paul Waldron Consulting, West Nyack, NY ABSTRACT Many programmers use SAS macro language to manipulate lists of variable names. They

More information

SAS Data Libraries. Definition CHAPTER 26

SAS Data Libraries. Definition CHAPTER 26 385 CHAPTER 26 SAS Data Libraries Definition 385 Library Engines 387 Library Names 388 Physical Names and Logical Names (Librefs) 388 Assigning Librefs 388 Associating and Clearing Logical Names (Librefs)

More information

The Power of PROC SQL Techniques and SAS Dictionary Tables in Handling Data

The Power of PROC SQL Techniques and SAS Dictionary Tables in Handling Data Paper PO31 The Power of PROC SQL Techniques and SAS Dictionary Tables in Handling Data MaryAnne DePesquo Hope, Health Services Advisory Group, Phoenix, Arizona Fen Fen Li, Health Services Advisory Group,

More information

... ) city (city, cntyid, area, pop,.. )

... ) city (city, cntyid, area, pop,.. ) PaperP829 PROC SQl - Is it a Required Tool for Good SAS Programming? Ian Whitlock, Westat Abstract No one SAS tool can be the answer to all problems. However, it should be hard to consider a SAS programmer

More information

Macros from Beginning to Mend A Simple and Practical Approach to the SAS Macro Facility

Macros from Beginning to Mend A Simple and Practical Approach to the SAS Macro Facility Macros from Beginning to Mend A Simple and Practical Approach to the SAS Macro Facility Michael G. Sadof, MGS Associates, Inc., Bethesda, MD. ABSTRACT The macro facility is an important feature of the

More information

STEP 1 - /*******************************/ /* Manipulate the data files */ /*******************************/ <<SAS DATA statements>>

STEP 1 - /*******************************/ /* Manipulate the data files */ /*******************************/ <<SAS DATA statements>> Generalized Report Programming Techniques Using Data-Driven SAS Code Kathy Hardis Fraeman, A.K. Analytic Programming, L.L.C., Olney, MD Karen G. Malley, Malley Research Programming, Inc., Rockville, MD

More information

WHAT ARE SASHELP VIEWS?

WHAT ARE SASHELP VIEWS? Paper PN13 There and Back Again: Navigating between a SASHELP View and the Real World Anita Rocha, Center for Studies in Demography and Ecology University of Washington, Seattle, WA ABSTRACT A real strength

More information

Acknowledgments xi Preface xiii About the Author xv About This Book xvii New in the Macro Language xxi

Acknowledgments xi Preface xiii About the Author xv About This Book xvii New in the Macro Language xxi Contents Part 1 Acknowledgments xi Preface xiii About the Author xv About This Book xvii New in the Macro Language xxi Macro Basics Chapter 1 Introduction 3 1.1 Macro Facility Overview 3 1.2 Terminology

More information

Tales from the Help Desk 6: Solutions to Common SAS Tasks

Tales from the Help Desk 6: Solutions to Common SAS Tasks SESUG 2015 ABSTRACT Paper BB-72 Tales from the Help Desk 6: Solutions to Common SAS Tasks Bruce Gilsen, Federal Reserve Board, Washington, DC In 30 years as a SAS consultant at the Federal Reserve Board,

More information

A SAS Macro Utility to Modify and Validate RTF Outputs for Regional Analyses Jagan Mohan Achi, PPD, Austin, TX Joshua N. Winters, PPD, Rochester, NY

A SAS Macro Utility to Modify and Validate RTF Outputs for Regional Analyses Jagan Mohan Achi, PPD, Austin, TX Joshua N. Winters, PPD, Rochester, NY PharmaSUG 2014 - Paper BB14 A SAS Macro Utility to Modify and Validate RTF Outputs for Regional Analyses Jagan Mohan Achi, PPD, Austin, TX Joshua N. Winters, PPD, Rochester, NY ABSTRACT Clinical Study

More information

A Second Look at SAS Macro Design Issues Ian Whitlock, Kennett Square, PA

A Second Look at SAS Macro Design Issues Ian Whitlock, Kennett Square, PA Paper 244-29 A Second Look at SAS Macro Design Issues Ian Whitlock, Kennett Square, PA ABSTRACT At SUGI 27 the author presented a paper "SAS Macro Design Issues" as a Beginning Tutorial. The use of names

More information

Tales from the Help Desk 5: Yet More Solutions for Common SAS Mistakes Bruce Gilsen, Federal Reserve Board

Tales from the Help Desk 5: Yet More Solutions for Common SAS Mistakes Bruce Gilsen, Federal Reserve Board Tales from the Help Desk 5: Yet More Solutions for Common SAS Mistakes Bruce Gilsen, Federal Reserve Board INTRODUCTION In 25 years as a SAS consultant at the Federal Reserve Board, I have seen SAS users

More information

RUN_MACRO Run! With PROC FCMP and the RUN_MACRO Function from SAS 9.2, Your SAS Programs Are All Grown Up

RUN_MACRO Run! With PROC FCMP and the RUN_MACRO Function from SAS 9.2, Your SAS Programs Are All Grown Up ABSTRACT Paper BON-02 RUN_MACRO Run! With PROC FCMP and the RUN_MACRO Function from SAS 9.2, Your SAS Programs Are All Grown Up Dylan Ellis, Mathematica Policy Research, Washington, DC When SAS first came

More information

Changes and Enhancements

Changes and Enhancements vii Introduction This section describes the host-specific features of SAS software under OS/390 that have been implemented or enhanced since the 6.09 Enhanced Release. Note: Information about changes and

More information

BreakOnWord: A Macro for Partitioning Long Text Strings at Natural Breaks Richard Addy, Rho, Chapel Hill, NC Charity Quick, Rho, Chapel Hill, NC

BreakOnWord: A Macro for Partitioning Long Text Strings at Natural Breaks Richard Addy, Rho, Chapel Hill, NC Charity Quick, Rho, Chapel Hill, NC PharmaSUG 2014 - Paper CC20 BreakOnWord: A Macro for Partitioning Long Text Strings at Natural Breaks Richard Addy, Rho, Chapel Hill, NC Charity Quick, Rho, Chapel Hill, NC ABSTRACT Breaking long text

More information

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection 1 Files 1.1 File functions Opening Files : The function fopen opens a file and returns a FILE pointer. FILE *fopen( const char * filename, const char * mode ); The allowed modes for fopen are as follows

More information

The Demystification of a Great Deal of Files

The Demystification of a Great Deal of Files SESUG 2016 ABSTRACT Paper -AD239 The Demystification of a Great Deal of Files Chao-Ying Hsieh, Southern Company Services, Inc. Atlanta, GA Our input data are sometimes stored in external flat files rather

More information

Introduction to file management

Introduction to file management 1 Introduction to file management Some application require input to be taken from a file and output is required to be stored in a file. The C language provides the facility of file input-output operations.

More information

Program Validation: Logging the Log

Program Validation: Logging the Log Program Validation: Logging the Log Adel Fahmy, Symbiance Inc., Princeton, NJ ABSTRACT Program Validation includes checking both program Log and Logic. The program Log should be clear of any system Error/Warning

More information

SAS Programming Techniques for Manipulating Metadata on the Database Level Chris Speck, PAREXEL International, Durham, NC

SAS Programming Techniques for Manipulating Metadata on the Database Level Chris Speck, PAREXEL International, Durham, NC PharmaSUG2010 - Paper TT06 SAS Programming Techniques for Manipulating Metadata on the Database Level Chris Speck, PAREXEL International, Durham, NC ABSTRACT One great leap that beginning and intermediate

More information

Taming a Spreadsheet Importation Monster

Taming a Spreadsheet Importation Monster SESUG 2013 Paper BtB-10 Taming a Spreadsheet Importation Monster Nat Wooding, J. Sargeant Reynolds Community College ABSTRACT As many programmers have learned to their chagrin, it can be easy to read Excel

More information

SAS CURRICULUM. BASE SAS Introduction

SAS CURRICULUM. BASE SAS Introduction SAS CURRICULUM BASE SAS Introduction Data Warehousing Concepts What is a Data Warehouse? What is a Data Mart? What is the difference between Relational Databases and the Data in Data Warehouse (OLTP versus

More information

Quick Data Definitions Using SQL, REPORT and PRINT Procedures Bradford J. Danner, PharmaNet/i3, Tennessee

Quick Data Definitions Using SQL, REPORT and PRINT Procedures Bradford J. Danner, PharmaNet/i3, Tennessee ABSTRACT PharmaSUG2012 Paper CC14 Quick Data Definitions Using SQL, REPORT and PRINT Procedures Bradford J. Danner, PharmaNet/i3, Tennessee Prior to undertaking analysis of clinical trial data, in addition

More information

KEYWORDS Metadata, macro language, CALL EXECUTE, %NRSTR, %TSLIT

KEYWORDS Metadata, macro language, CALL EXECUTE, %NRSTR, %TSLIT MWSUG 2017 - Paper BB15 Building Intelligent Macros: Driving a Variable Parameter System with Metadata Arthur L. Carpenter, California Occidental Consultants, Anchorage, Alaska ABSTRACT When faced with

More information

User-Written DATA Step Functions Jason Secosky, SAS Institute Inc., Cary, NC

User-Written DATA Step Functions Jason Secosky, SAS Institute Inc., Cary, NC Paper TU10 User-Written DATA Step Functions Jason Secosky, SAS Institute Inc., Cary, NC Presented at SESUG 2007 by Robert Ray of SAS ABSTRACT For years, users have asked for the ability to write functions

More information

Tired of CALL EXECUTE? Try DOSUBL

Tired of CALL EXECUTE? Try DOSUBL ABSTRACT SESUG Paper BB-132-2017 Tired of CALL EXECUTE? Try DOSUBL Jueru Fan, PPD, Morrisville, NC DOSUBL was first introduced as a function in SAS V9.3. It enables the immediate execution of SAS code

More information

SAS Macro. SAS Training Courses. Amadeus Software Ltd

SAS Macro. SAS Training Courses. Amadeus Software Ltd SAS Macro SAS Training Courses By Amadeus Software Ltd AMADEUS SOFTWARE LIMITED SAS TRAINING Amadeus have been delivering SAS Training since 1989 and our aim is to provide you with best quality SAS training

More information

Planting Your Rows: Using SAS Formats to Make the Generation of Zero- Filled Rows in Tables Less Thorny

Planting Your Rows: Using SAS Formats to Make the Generation of Zero- Filled Rows in Tables Less Thorny Planting Your Rows: Using SAS Formats to Make the Generation of Zero- Filled Rows in Tables Less Thorny Kathy Hardis Fraeman, United BioSource Corporation, Bethesda, MD ABSTRACT Often tables or summary

More information

ABC Macro and Performance Chart with Benchmarks Annotation

ABC Macro and Performance Chart with Benchmarks Annotation Paper CC09 ABC Macro and Performance Chart with Benchmarks Annotation Jing Li, AQAF, Birmingham, AL ABSTRACT The achievable benchmark of care (ABC TM ) approach identifies the performance of the top 10%

More information

So Much Data, So Little Time: Splitting Datasets For More Efficient Run Times and Meeting FDA Submission Guidelines

So Much Data, So Little Time: Splitting Datasets For More Efficient Run Times and Meeting FDA Submission Guidelines Paper TT13 So Much Data, So Little Time: Splitting Datasets For More Efficient Run Times and Meeting FDA Submission Guidelines Anthony Harris, PPD, Wilmington, NC Robby Diseker, PPD, Wilmington, NC ABSTRACT

More information

Paper B GENERATING A DATASET COMPRISED OF CUSTOM FORMAT DETAILS

Paper B GENERATING A DATASET COMPRISED OF CUSTOM FORMAT DETAILS Paper B07-2009 Eliminating Redundant Custom Formats (or How to Really Take Advantage of Proc SQL, Proc Catalog, and the Data Step) Philip A. Wright, University of Michigan, Ann Arbor, MI ABSTRACT Custom

More information

Open Problem for SUAVe User Group Meeting, November 26, 2013 (UVic)

Open Problem for SUAVe User Group Meeting, November 26, 2013 (UVic) Open Problem for SUAVe User Group Meeting, November 26, 2013 (UVic) Background The data in a SAS dataset is organized into variables and observations, which equate to rows and columns. While the order

More information

Building Sequential Programs for a Routine Task with Five SAS Techniques

Building Sequential Programs for a Routine Task with Five SAS Techniques ABSTRACT SESUG Paper BB-139-2017 Building Sequential Programs for a Routine Task with Five SAS Techniques Gongmei Yu and Paul LaBrec, 3M Health Information Systems. When a task needs to be implemented

More information

A Maintenance-Free Menu Driven Closure System by Stephen M. Noga, Rho, Inc.

A Maintenance-Free Menu Driven Closure System by Stephen M. Noga, Rho, Inc. A Maintenance-Free Menu Driven Closure System by Stephen M. Noga, Rho, Inc. Introduction As a clinical trial nears closure, a series of data validation programs are run, sometimes individually, and sometimes

More information

Validation Summary using SYSINFO

Validation Summary using SYSINFO Validation Summary using SYSINFO Srinivas Vanam Mahipal Vanam Shravani Vanam Percept Pharma Services, Bridgewater, NJ ABSTRACT This paper presents a macro that produces a Validation Summary using SYSINFO

More information

SQL Metadata Applications: I Hate Typing

SQL Metadata Applications: I Hate Typing SQL Metadata Applications: I Hate Typing Hannah Fresques, MDRC, New York, NY ABSTRACT This paper covers basics of metadata in SQL and provides useful applications, including: finding variables on one or

More information

ENG120. Misc. Topics

ENG120. Misc. Topics ENG120 Misc. Topics Topics Files in C Using Command-Line Arguments Typecasting Working with Multiple source files Conditional Operator 2 Files and Streams C views each file as a sequence of bytes File

More information

Using Different Methods for Accessing Non-SAS Data to Build and Incrementally Update That Data Warehouse

Using Different Methods for Accessing Non-SAS Data to Build and Incrementally Update That Data Warehouse Paper DM-01 Using Different Methods for Accessing Non-SAS Data to Build and Incrementally Update That Data Warehouse Abstract Ben Cochran, The Bedford Group, Raleigh, NC Often SAS users need to access

More information

PharmaSUG China. Systematically Reordering Axis Major Tick Values in SAS Graph Brian Shen, PPDI, ShangHai

PharmaSUG China. Systematically Reordering Axis Major Tick Values in SAS Graph Brian Shen, PPDI, ShangHai PharmaSUG China Systematically Reordering Axis Major Tick Values in SAS Graph Brian Shen, PPDI, ShangHai ABSTRACT Once generating SAS graphs, it is a headache to programmers to reorder the axis tick values

More information

STATION

STATION ------------------------------STATION 1------------------------------ 1. Which of the following statements displays all user-defined macro variables in the SAS log? a) %put user=; b) %put user; c) %put

More information

APPENDIX 4 Migrating from QMF to SAS/ ASSIST Software. Each of these steps can be executed independently.

APPENDIX 4 Migrating from QMF to SAS/ ASSIST Software. Each of these steps can be executed independently. 255 APPENDIX 4 Migrating from QMF to SAS/ ASSIST Software Introduction 255 Generating a QMF Export Procedure 255 Exporting Queries from QMF 257 Importing QMF Queries into Query and Reporting 257 Alternate

More information

Make it a Date! Setting up a Master Date View in SAS

Make it a Date! Setting up a Master Date View in SAS SCSUG Paper 19-2017 Make it a Date! Setting up a Master Date View in SAS Crystal Carel, MPH¹ ² ¹STEEEP Analytics, Baylor Scott & White Health, Dallas, TX ²Northern Illinois University, College of Health

More information

MOBILE MACROS GET UP TO SPEED SOMEWHERE NEW FAST Author: Patricia Hettinger, Data Analyst Consultant Oakbrook Terrace, IL

MOBILE MACROS GET UP TO SPEED SOMEWHERE NEW FAST Author: Patricia Hettinger, Data Analyst Consultant Oakbrook Terrace, IL MOBILE MACROS GET UP TO SPEED SOMEWHERE NEW FAST Author: Patricia Hettinger, Data Analyst Consultant Oakbrook Terrace, IL ABSTRACT: Have you ever been faced with this scenario? It s your first day on the

More information

Different Methods for Accessing Non-SAS Data to Build and Incrementally Update That Data Warehouse

Different Methods for Accessing Non-SAS Data to Build and Incrementally Update That Data Warehouse Different Methods for Accessing Non-SAS Data to Build and Incrementally Update That Data Warehouse Ben Cochran, The Bedford Group, Raleigh, NC Abstract Often SAS users need to access data from non- SAS

More information

Data Quality Review for Missing Values and Outliers

Data Quality Review for Missing Values and Outliers Paper number: PH03 Data Quality Review for Missing Values and Outliers Ying Guo, i3, Indianapolis, IN Bradford J. Danner, i3, Lincoln, NE ABSTRACT Before performing any analysis on a dataset, it is often

More information

Unlock SAS Code Automation with the Power of Macros

Unlock SAS Code Automation with the Power of Macros SESUG 2015 ABSTRACT Paper AD-87 Unlock SAS Code Automation with the Power of Macros William Gui Zupko II, Federal Law Enforcement Training Centers SAS code, like any computer programming code, seems to

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

Getting it Done with PROC TABULATE

Getting it Done with PROC TABULATE ABSTRACT Getting it Done with PROC TABULATE Michael J. Williams, ICON Clinical Research, San Francisco, CA The task of displaying statistical summaries of different types of variables in a single table

More information

CHAPTER 13 Importing and Exporting External Data

CHAPTER 13 Importing and Exporting External Data 127 CHAPTER 13 Importing and Exporting External Data Chapter Overview 127 Exporting a File 127 Instructions 128 Exiting This Task 130 Importing Data from a Flat File 130 Instructions 130 Chapter Overview

More information

SELF-MODIFYING SAS PROGRAMS: A DATA STEP INTERFACE

SELF-MODIFYING SAS PROGRAMS: A DATA STEP INTERFACE SELF-MODIFYING SAS PROGRAMS: A DATA STEP INTERFACE S. David Riba, JADE Tech, Inc., Clearwater, FL ABSTRACT There are many situations where it is useful to have a SAse program modify itself during execution.

More information

Exploring the SAS Macro Function %SYSFUNC

Exploring the SAS Macro Function %SYSFUNC Paper CC11 Exploring the SAS Macro Function %SYSFUNC Lin Yan and Helen Wang Department of Scientific Programming Merck Research Labs, Merck & Co., Inc. Rahway, New Jersey 07065 ABSTRACT The SAS macro function

More information

Get Started Writing SAS Macros Luisa Hartman, Jane Liao, Merck Sharp & Dohme Corp.

Get Started Writing SAS Macros Luisa Hartman, Jane Liao, Merck Sharp & Dohme Corp. Get Started Writing SAS Macros Luisa Hartman, Jane Liao, Merck Sharp & Dohme Corp. ABSTRACT The SAS Macro Facility is a tool which lends flexibility to your SAS code and promotes easier maintenance. It

More information

Macro Quoting: Which Function Should We Use? Pengfei Guo, MSD R&D (China) Co., Ltd., Shanghai, China

Macro Quoting: Which Function Should We Use? Pengfei Guo, MSD R&D (China) Co., Ltd., Shanghai, China PharmaSUG China 2016 - Paper 81 Macro Quoting: Which Function Should We Use? Pengfei Guo, MSD R&D (China) Co., Ltd., Shanghai, China ABSTRACT There are several macro quoting functions in SAS and even some

More information

Calculating Cardinality Ratio in Two Steps

Calculating Cardinality Ratio in Two Steps MWSUG 2016 Paper TT03 Calculating Cardinality Ratio in Two Steps Ronald J. Fehd, Stakana Analytics Abstract Description: Purpose: Audience: Keywords: The cardinality of a set is the number of elements

More information

Know Thy Data : Techniques for Data Exploration

Know Thy Data : Techniques for Data Exploration Know Thy Data : Techniques for Data Exploration Montreal SAS Users Group Wednesday, 29 May 2018 13:50-14:30 PM Andrew T. Kuligowski, Charu Shankar AGENDA Part 1- Easy Ways to know your data Part 2 - Powerful

More information

Standard File Pointers

Standard File Pointers 1 Programming in C Standard File Pointers Assigned to console unless redirected Standard input = stdin Used by scan function Can be redirected: cmd < input-file Standard output = stdout Used by printf

More information

Paper S Data Presentation 101: An Analyst s Perspective

Paper S Data Presentation 101: An Analyst s Perspective Paper S1-12-2013 Data Presentation 101: An Analyst s Perspective Deanna Chyn, University of Michigan, Ann Arbor, MI Anca Tilea, University of Michigan, Ann Arbor, MI ABSTRACT You are done with the tedious

More information

Posters. Paper

Posters. Paper Paper 212-26 Using SAS/AF to Create a SAS Program File Explorer Rob Nelson, Centers for Disease Control and Prevention, Atlanta, GA Janet Royalty, Centers for Disease Control and Prevention, Atlanta, GA

More information

SD10 A SAS MACRO FOR PERFORMING BACKWARD SELECTION IN PROC SURVEYREG

SD10 A SAS MACRO FOR PERFORMING BACKWARD SELECTION IN PROC SURVEYREG Paper SD10 A SAS MACRO FOR PERFORMING BACKWARD SELECTION IN PROC SURVEYREG Qixuan Chen, University of Michigan, Ann Arbor, MI Brenda Gillespie, University of Michigan, Ann Arbor, MI ABSTRACT This paper

More information

Using PROC SQL to Calculate FIRSTOBS David C. Tabano, Kaiser Permanente, Denver, CO

Using PROC SQL to Calculate FIRSTOBS David C. Tabano, Kaiser Permanente, Denver, CO Using PROC SQL to Calculate FIRSTOBS David C. Tabano, Kaiser Permanente, Denver, CO ABSTRACT The power of SAS programming can at times be greatly improved using PROC SQL statements for formatting and manipulating

More information

PhUSE US Connect 2018 Paper CT06 A Macro Tool to Find and/or Split Variable Text String Greater Than 200 Characters for Regulatory Submission Datasets

PhUSE US Connect 2018 Paper CT06 A Macro Tool to Find and/or Split Variable Text String Greater Than 200 Characters for Regulatory Submission Datasets PhUSE US Connect 2018 Paper CT06 A Macro Tool to Find and/or Split Variable Text String Greater Than 200 Characters for Regulatory Submission Datasets Venkata N Madhira, Shionogi Inc, Florham Park, USA

More information

An Introduction to SAS Macros

An Introduction to SAS Macros An Introduction to SAS Macros Expanded token SAS Program (Input Stack) SAS Wordscanner (Tokenization) Non-Macro (Tokens) SAS Compiler % and & Triggers Macro Facility Steven First, President 2997 Yarmouth

More information

Posters. Workarounds for SASWare Ballot Items Jack Hamilton, First Health, West Sacramento, California USA. Paper

Posters. Workarounds for SASWare Ballot Items Jack Hamilton, First Health, West Sacramento, California USA. Paper Paper 223-25 Workarounds for SASWare Ballot Items Jack Hamilton, First Health, West Sacramento, California USA ABSTRACT As part of its effort to insure that SAS Software is useful to its users, SAS Institute

More information

Mimicking the Data Step Dash and Double Dash in PROC SQL Arlene Amodeo, Law School Admission Council, Newtown, PA

Mimicking the Data Step Dash and Double Dash in PROC SQL Arlene Amodeo, Law School Admission Council, Newtown, PA ABSTRACT Mimicking the Data Step Dash and Double Dash in PROC SQL Arlene Amodeo, Law School Admission Council, Newtown, PA The SQL procedure is a powerful and versatile procedure in SAS that allows the

More information

Customized Flowcharts Using SAS Annotation Abhinav Srivastva, PaxVax Inc., Redwood City, CA

Customized Flowcharts Using SAS Annotation Abhinav Srivastva, PaxVax Inc., Redwood City, CA ABSTRACT Customized Flowcharts Using SAS Annotation Abhinav Srivastva, PaxVax Inc., Redwood City, CA Data visualization is becoming a trend in all sectors where critical business decisions or assessments

More information

e. That's accomplished with:

e. That's accomplished with: Make Your Life a Little Easier: A Collection of SAs Macro Utilities Pete Lund, Northwest Crime and Social Research, Olympia, WA ABSTRACT SAs Macros are used in a variety of ways: to automate the generation

More information

Using SAS Files CHAPTER 3

Using SAS Files CHAPTER 3 55 CHAPTER 3 Using SAS Files Introduction to SAS Files 56 What Is a SAS File? 56 Types of SAS Files 57 Using Short or Long File Extensions in SAS Libraries 58 SAS Data Sets (Member Type: Data or View)

More information

A Simple Framework for Sequentially Processing Hierarchical Data Sets for Large Surveys

A Simple Framework for Sequentially Processing Hierarchical Data Sets for Large Surveys A Simple Framework for Sequentially Processing Hierarchical Data Sets for Large Surveys Richard L. Downs, Jr. and Pura A. Peréz U.S. Bureau of the Census, Washington, D.C. ABSTRACT This paper explains

More information

Abstract. Background. Summary of method. Using SAS to determine file and space usage in UNIX. Title: Mike Montgomery [MIS Manager, MTN (South Africa)]

Abstract. Background. Summary of method. Using SAS to determine file and space usage in UNIX. Title: Mike Montgomery [MIS Manager, MTN (South Africa)] Title: Author: Using SAS to determine file and space usage in UNIX Mike Montgomery [MIS Manager, MTN (South Africa)] Abstract The paper will show tools developed to manage a proliferation of SAS files

More information

1 Files to download. 3 Macro to list the highest and lowest N data values. 2 Reading in the example data file

1 Files to download. 3 Macro to list the highest and lowest N data values. 2 Reading in the example data file 1 2 22S:172 Lab session 10 Macros for data cleaning July 17, 2003 GENDER VISIT HR SBP DBP DX AE = "Gender" = "Visit Date" = "Heart Rate" = "Systolic Blood Pressure" = "Diastolic Blood Pressure" = "Diagnosis

More information

INTRODUCTION TO SAS HOW SAS WORKS READING RAW DATA INTO SAS

INTRODUCTION TO SAS HOW SAS WORKS READING RAW DATA INTO SAS TO SAS NEED FOR SAS WHO USES SAS WHAT IS SAS? OVERVIEW OF BASE SAS SOFTWARE DATA MANAGEMENT FACILITY STRUCTURE OF SAS DATASET SAS PROGRAM PROGRAMMING LANGUAGE ELEMENTS OF THE SAS LANGUAGE RULES FOR SAS

More information

TLF Management Tools: SAS programs to help in managing large number of TLFs. Eduard Joseph Siquioco, PPD, Manila, Philippines

TLF Management Tools: SAS programs to help in managing large number of TLFs. Eduard Joseph Siquioco, PPD, Manila, Philippines PharmaSUG China 2018 Paper AD-58 TLF Management Tools: SAS programs to help in managing large number of TLFs ABSTRACT Eduard Joseph Siquioco, PPD, Manila, Philippines Managing countless Tables, Listings,

More information

Simplifying Your %DO Loop with CALL EXECUTE Arthur Li, City of Hope National Medical Center, Duarte, CA

Simplifying Your %DO Loop with CALL EXECUTE Arthur Li, City of Hope National Medical Center, Duarte, CA PharmaSUG 2017 BB07 Simplifying Your %DO Loop with CALL EXECUTE Arthur Li, City of Hope National Medical Center, Duarte, CA ABSTRACT One often uses an iterative %DO loop to execute a section of a macro

More information

A Tutorial on the SAS Macro Language

A Tutorial on the SAS Macro Language HW152 SESUG 2015 A Tutorial on the SAS Macro Language John J. Cohen, Advanced Data Concepts LLC, Newark, DE ABSTRACT The SAS Macro language is another language that rests on top of regular SAS code. If

More information