Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
SAS macro program initial upload
  • Loading branch information
chris-swenson committed Nov 14, 2020
1 parent 7ea092c commit 46a8318
Show file tree
Hide file tree
Showing 83 changed files with 14,055 additions and 0 deletions.
65 changes: 65 additions & 0 deletions addformatlib.sas
@@ -0,0 +1,65 @@
%macro AddFormatLib(libs) / des="Add a library to the fmtsearch option";

/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: AddFormatLib
Author: Chris Swenson
Created: 2010-09-29
Purpose: Add a library to the format search system option (fmtsearch)
Arguments: libs - one or more libraries to add to the format search option
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
2011-08-19 CAS Revised to scan through argument to match the order
specified by the user.
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/

%let libs=%upcase(&libs);

%if "&libs"="" %then %do;
%put %str(E)RROR: No arguments specified.;
%return;
%end;

%local count fmtsearch addlibs i current changed;
%let count=%sysfunc(countw(&libs, %str( )));
%put NOTE: &COUNT references specified.;

%let fmtsearch=%upcase(%sysfunc(getoption(fmtsearch)));
%if "%substr(&FMTSEARCH, 1, 1)"="("
%then %let fmtsearch=%substr(&FMTSEARCH, 2, %length(%sysfunc(getoption(fmtsearch)))-2);

/* REVISION 2011-08-19 CAS: Revised to go backwords through list */
%do i=&COUNT %to 1 %by -1;

%let current=%scan(&libs, &i, %str( ));

%if %sysfunc(libref(&current)) ne 0 %then %do;
%put %str(E)RROR: Specified library &current does not exist.;
%return;
%end;

%let changed=%sysfunc(tranwrd(&fmtsearch, %str( ), %str(*)));

%if %index(*&CHANGED*,*&CURRENT*)>0
%then %put NOTE: Specified library &current is already specified on the FMTSEARCH option.;
%else %let addlibs=&CURRENT &ADDLIBS;

%end;

option fmtsearch=(&fmtsearch &addlibs);

%put NOTE: Format Search Option (fmtsearch) = %sysfunc(getoption(fmtsearch));

%mend AddFormatLib;
64 changes: 64 additions & 0 deletions addsasauto.sas
@@ -0,0 +1,64 @@
%macro AddSASAuto(ref) / des="Add a fileref to the SASAutos option";

/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: AddSASAuto
Author: Chris Swenson
Created: 2010-10-18
Purpose: Add a fileref to the SAS autocall macro option (SASAUTOS)
Arguments: ref - one or more filerefs to add to the option
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
2011-08-19 CAS Revised to scan through argument to match the order
specified by the user.
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/

%let ref=%upcase(&ref);

%if "%superq(ref)"="" %then %do;
%put %str(E)RROR: No arguments specified.;
%return;
%end;

%local count sasautos addref i current changed;
%let count=%sysfunc(countw(&ref, %str( )));
%put NOTE: &COUNT references specified.;

%let sasautos=%upcase(%sysfunc(getoption(sasautos)));
%if "%substr(&SASAUTOS, 1, 1)"="("
%then %let sasautos=%substr(&SASAUTOS, 2, %length(&SASAUTOS)-2);

%do i=&COUNT %to 1 %by -1;

%let current=%scan(&ref, &i, %str( ));

%if %sysfunc(fileref(&current)) ne 0 %then %do;
%put %str(E)RROR: Specified fileref &current does not exist.;
%return;
%end;

%let changed=%sysfunc(tranwrd(&sasautos, %str( ), %str(*)));

%if %index(*&CHANGED*,*&CURRENT*)>0
%then %put NOTE: Specified fileref &current is already specified on the SASAUTOS option.;
%else %let addref=&current &addref;

%end;

option sasautos=(&addref &sasautos);

%put NOTE: SAS Autocall Option (SASAutos) = %sysfunc(getoption(sasautos));

%mend AddSASAuto;
45 changes: 45 additions & 0 deletions agecalc.sas
@@ -0,0 +1,45 @@
%macro agecalc(date,dob) / des='Calculate age';

/****************************************************************************
BEGIN MACRO HEADER
****************************************************************************
Name: AgeCalc
Author: Chris Swenson
Created: 2009-04-29
Purpose: Calculate age based on documentation found at
http://support.sas.com/kb/24/808.html
Arguments: date - date to calculate the age from
dob - date of birth of the person(s) in question
Usage: Use the macro as a function within a data step or procedure,
for example: age=%AgeCalc(today(), DateOfBirth)
Caution: The formula will not work for people born on Feb 29 who
celebrate on Feb 28. This code handles the celebration day as
Mar 01. The code will also not work where/when the Gregorian
calendar was not in use. See the online documenation for
futher details.
Notes: The intck function returns the number of months betweeen the
DOB and the date. The day functions return a 0 or 1 if the day
of the DOB is greater than the day of the date to correct for
leap years. Dividing by 12 returns the number of years, and
the floor function rounds down for colloquial use.
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
YYYY-MM-DD III Please use this format and insert new entries above
****************************************************************************
END MACRO HEADER
****************************************************************************/

floor( (intck('month', &dob, &date) - ( day(&date) < day(&dob) )) / 12)

%mend agecalc;
70 changes: 70 additions & 0 deletions blankfind.sas
@@ -0,0 +1,70 @@
%macro BlankFind(varlist) / des="Write code to find blank arguments";

/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: BlankFind
Author: Chris Swenson
Created: 2010-08-19
Purpose: Generate code the find blank macro program arguments. This can be
used to generate "argument checks" at the beginning of a macro
program to ensure that all arguments are populated. The code
cannot be used to do the check because it is best to avoid nested
macros.
Arguments: varlist - the list of macro arguments to generate checks for,
separated by a space
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/

%if "&VARLIST"="" %then %do;
%put %str(E)RROR: No variable list specified.;
%return;
%end;

%local num i var;

%let num=%sysfunc(countw(&VARLIST));

%put ;

filename _cb_ clipbrd;

data _null_;
format temp1 temp2 $250.;
file _cb_;

%do i=1 %to &NUM;

%let var=%upcase(%scan(&VARLIST, &I, %str( )));

temp1='%if %superq(' || "&VAR" || ')=%str() %then %do;';
temp2='%put %str(E)RROR: No argument specified for ' || "&VAR" || '.;';

put temp1;
put ' ' temp2;
put " %return;";
put "%end;";

%end;

run;

filename _cb_ clear;

%put ;
%put NOTE: The generated code has been copied to the clipboard.;
%put NOTE- Paste the code in the appropriate area.;

%mend BlankFind;
38 changes: 38 additions & 0 deletions bmicalc.sas
@@ -0,0 +1,38 @@
%macro BmiCalc(oz,in) / des='Calculate BMI';

/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: BmiCalc
Author: Chris Swenson
Created: 2012-01-03
Purpose: Calculate BMI based on weight in ounces and height in inches.
Arguments: oz - weight (in ounces) variable
in - height (in inches) variable
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/

703*(&OZ/16)/(&IN**2)

%mend BmiCalc;

/*
data test;
format oz in 4.;
oz=185*16;
in=12*5+10;
bmi=%BmiCalc(oz, in);
run;
*/

0 comments on commit 46a8318

Please sign in to comment.