SlideShare a Scribd company logo
SAS macro to Create / Remove a PC Directory...Here's a SAS macro to Create and Remove a PC Directory... Often we ignore Notes and warning in the SAS log when we try to create/remove a directory that does/doesn't exist...This macro first checks for the existence of the directory and then create/delete it or else put a message to the SAS log...try it out :-) /* Macro to Create a directory */%macro CheckandCreateDir(dir);    options noxwait;    %local rc fileref ;    %let rc = %sysfunc(filename(fileref,&dir)) ;       %if %sysfunc(fexist(&fileref)) %then       %put The directory \"
&dir\"
 already exists ;    %else      %do ;          %sysexec mkdir \"
&dir\"
 ;          %if &sysrc eq 0 %then %put The directory &dir has been created. ; Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-remove-pc-directory.html Ways to Count the Number of Obs in a dataset and pass it into a macro variable...Well...there are many ways of getting the observation count into a macro variable...but there a few pros and cons in those methods...1. using sql with count(*)..  eg.         proc sql;              select count(*) into :macvar             from dsn;         quit; pros: simple to understand and develop cons: you need to read the dataset in its entirety which requires processing power here...2. datastep  eg.        data new;          set old nobs=num;          call symputx('macvar',num);       run;Read more @ http://sastechies.blogspot.com/2009/11/ways-to-count-number-of-obs-in-dataset.html SAS macro to split dataset by the number of Observations specifiedSuppose there was a large dataset....This SAS macro program splits the dataset by the number of observations mentioned...macro name%split(DatasetName, No ofobservation to split by)/* creating a dataset with 100000 observations*/data dsn;do i=1 to 100000;output;end;run;%macro split(dsn,splitby);data _null_;set &dsn nobs=num;Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-split-dataset-by-number-of.html SAS macro to reorder dataset variables in alphabetic order...How do you reorder variables in a dataset...I get this many a times.... Here's a macro for you to achieve it...For example I've used a dataset sashelp.flags and created some more variables with variety of variables with names upper / lower cases and _'s to demonstrate the reorder macro....   Please try this macro for yourself and let me know your suggestions.... /* Example dataset with variety of variable names */  data flags; set sashelp.flags; a=2; b=4; Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-reorder-dataset-variables.htmlUse SAS function Propcase() to streamline Google ContactsYou might think I am crazy...but I have been using this macro for a long time to fix some contacts in my Google Contacts...I get a little irritated when I can't find a particular person by email...so I wrote this macro...This macro takes for Input a .csv file that is exported from Google Contacts and outputs a file that is ready to be imported to Google Contacts....often I wanted to have Names in the proper case...Try it yourself and let me know if it needs any tweaks...Propcase in SAS Documentation.%macro organizeGoogleContacts(infile,outfile);/*Import your contacts into SAS */ data googlegroups;infile \"
&infile\"
 dlm=',' dsd lrecl=32767 firstobs=2;Read more @ http://sastechies.blogspot.com/2009/11/use-sas-function-propcase-to-streamline.html  SAS Macro to Create a delimited text file from a SAS dataset...A document that discusses SAS Macro to Create a delimited text file from a SAS data set.. options mprint; data one;  input id name :$20. amount ;  date=today();  format amount dollar10.2            date mmddyy10.;  label id=\"
Customer ID Number\"
;datalines;1 Grant   57.232 Michael 45.683 Tammy   53.21;Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-create-delimited-text-file.html SAS Macro to split a dataset into multiple datasets vertically with a common primary keyThis macro splits a dataset to multiple datasets vertically with a common primary key. For eg, a dataset has 400 fields and 20,000 records. If we can split the dataset into two, with 200 fields and 20,000 records in each dataset with a common field like loan number as primary key would be helpful to load the details for analysis. /**To be called like this...%splitdsnverticallykey(dsn,varperdsn,keyvars=);eg. %splitdsnverticallykey(sashelp.vtable,4,keyvars=memname libname); Where ----------- dsn - libname.datasetname to be splitvarperdsn - How many vars per dsn excluding the key variableskeyvars - specify the primary key variables*/ Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-split-dataset-into.html SAS Macro that reads the filenames  available at a particular directory on any FTP server (i.e. Windows Network  Drive/Unix/Mainframe)Here's a macro that reads the filenames available at a particular directory on any FTP server (i.e. Windows Network Drive/Unix/Mainframe)...For Windows network drives we use the Filename Pipe StatementFor Mainframe and Unix we use the FileName FTP protocol statement.For further reference please refer to Filename statements in SAS Documentation.First we need to create 2 Excel files ServerList.xls – 3 columns with servertype | host | sourcedirRead more @ http://sastechies.blogspot.com/2009/11/sas-macro-that-lists-files-at.html
Sas Macro Examples
Sas Macro Examples
Sas Macro Examples
Sas Macro Examples
Sas Macro Examples
Sas Macro Examples
Sas Macro Examples
Sas Macro Examples
Sas Macro Examples

More Related Content

PDF
Introduction To Sas
PPT
SAS Macros
PPT
Understanding SAS Data Step Processing
DOCX
Learn SAS Programming
PPTX
Proc SQL in SAS Enterprise Guide 4.3
DOCX
Base sas interview questions
PDF
Sas® Macro Design Patterns
PPT
Base SAS Statistics Procedures
Introduction To Sas
SAS Macros
Understanding SAS Data Step Processing
Learn SAS Programming
Proc SQL in SAS Enterprise Guide 4.3
Base sas interview questions
Sas® Macro Design Patterns
Base SAS Statistics Procedures

What's hot (20)

PPT
SAS Macros part 1
PDF
SAS cheat sheet
PPTX
SAS Mainframe -Program-Tips
PPT
Basics Of SAS Programming Language
PPT
Data Match Merging in SAS
PDF
Introduction to SAS Data Set Options
PPT
Improving Effeciency with Options in SAS
PPT
Utility Procedures in SAS
PPTX
Understanding sas data step processing.
PPT
SAS Macros part 4.1
PDF
Base SAS Full Sample Paper
PPT
SAS Macros part 2
PPT
SAS ODS HTML
PDF
Introduction to SAS
PPT
SAS BASICS
PPT
SAS Macros part 3
PDF
A Step-By-Step Introduction to SAS Report Procedure
PDF
Sas summary guide
PPT
INTRODUCTION TO SAS
SAS Macros part 1
SAS cheat sheet
SAS Mainframe -Program-Tips
Basics Of SAS Programming Language
Data Match Merging in SAS
Introduction to SAS Data Set Options
Improving Effeciency with Options in SAS
Utility Procedures in SAS
Understanding sas data step processing.
SAS Macros part 4.1
Base SAS Full Sample Paper
SAS Macros part 2
SAS ODS HTML
Introduction to SAS
SAS BASICS
SAS Macros part 3
A Step-By-Step Introduction to SAS Report Procedure
Sas summary guide
INTRODUCTION TO SAS
Ad

Viewers also liked (12)

PPT
SAS Proc SQL
PDF
Proc sql tips
PDF
Base SAS Exam Questions
PPTX
MACRO ENVIRONMENT BY JEET PAREKH
PDF
MANAGING MARKETS - Macro Environmental Forces and Marketing Mix / Commonwealt...
PPTX
Marketing management
PPTX
Micro marketing environment
PPT
SAS Functions
PPT
Arrays in SAS
PPSX
SAS TRAINING
PPT
Interviewing Basics
PDF
Approximating_probability_density_functions_for_the_Collective_Risk_Model
SAS Proc SQL
Proc sql tips
Base SAS Exam Questions
MACRO ENVIRONMENT BY JEET PAREKH
MANAGING MARKETS - Macro Environmental Forces and Marketing Mix / Commonwealt...
Marketing management
Micro marketing environment
SAS Functions
Arrays in SAS
SAS TRAINING
Interviewing Basics
Approximating_probability_density_functions_for_the_Collective_Risk_Model
Ad

Similar to Sas Macro Examples (20)

PDF
I need help with Applied Statistics and the SAS Programming Language.pdf
PPT
Sas classes in mumbai
PPT
Sas short course_presentation_11-4-09
PPT
Sas short course_presentation_11-4-09
PPT
BASE SAS Training presentation of coding
PDF
Introduction to sas
PDF
Analytics with SAS
PDF
Sas cheat
PPT
Prog1 chap1 and chap 2
PDF
SAS Internal Training
DOC
Introduction to SAS
PDF
Sas tips & tricks
PDF
PPTX
BAS 150 Lesson 4 Lecture
PPT
As08 Revised
PDF
Sas training-course-navi-mumbai-sas-course-provider-navi-mumbai
PPTX
Sas clinical training
PPT
Hechsp 001 Chapter 3
PPT
SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...
I need help with Applied Statistics and the SAS Programming Language.pdf
Sas classes in mumbai
Sas short course_presentation_11-4-09
Sas short course_presentation_11-4-09
BASE SAS Training presentation of coding
Introduction to sas
Analytics with SAS
Sas cheat
Prog1 chap1 and chap 2
SAS Internal Training
Introduction to SAS
Sas tips & tricks
BAS 150 Lesson 4 Lecture
As08 Revised
Sas training-course-navi-mumbai-sas-course-provider-navi-mumbai
Sas clinical training
Hechsp 001 Chapter 3
SAS Online Training by Real Time Working Professionals in USA,UK,India,Middle...

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
master seminar digital applications in india
PDF
Insiders guide to clinical Medicine.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Pre independence Education in Inndia.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Cell Types and Its function , kingdom of life
PDF
Basic Mud Logging Guide for educational purpose
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
RMMM.pdf make it easy to upload and study
PPTX
Cell Structure & Organelles in detailed.
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Sports Quiz easy sports quiz sports quiz
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pharma ospi slides which help in ospi learning
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
master seminar digital applications in india
Insiders guide to clinical Medicine.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Pre independence Education in Inndia.pdf
TR - Agricultural Crops Production NC III.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
Cell Types and Its function , kingdom of life
Basic Mud Logging Guide for educational purpose
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
01-Introduction-to-Information-Management.pdf
VCE English Exam - Section C Student Revision Booklet
RMMM.pdf make it easy to upload and study
Cell Structure & Organelles in detailed.
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Sports Quiz easy sports quiz sports quiz

Sas Macro Examples

  • 1. SAS macro to Create / Remove a PC Directory...Here's a SAS macro to Create and Remove a PC Directory... Often we ignore Notes and warning in the SAS log when we try to create/remove a directory that does/doesn't exist...This macro first checks for the existence of the directory and then create/delete it or else put a message to the SAS log...try it out :-) /* Macro to Create a directory */%macro CheckandCreateDir(dir);    options noxwait;    %local rc fileref ;    %let rc = %sysfunc(filename(fileref,&dir)) ;       %if %sysfunc(fexist(&fileref)) %then       %put The directory \" &dir\" already exists ;    %else      %do ;          %sysexec mkdir \" &dir\" ;          %if &sysrc eq 0 %then %put The directory &dir has been created. ; Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-remove-pc-directory.html Ways to Count the Number of Obs in a dataset and pass it into a macro variable...Well...there are many ways of getting the observation count into a macro variable...but there a few pros and cons in those methods...1. using sql with count(*)..  eg.         proc sql;              select count(*) into :macvar             from dsn;         quit; pros: simple to understand and develop cons: you need to read the dataset in its entirety which requires processing power here...2. datastep  eg.        data new;          set old nobs=num;          call symputx('macvar',num);       run;Read more @ http://sastechies.blogspot.com/2009/11/ways-to-count-number-of-obs-in-dataset.html SAS macro to split dataset by the number of Observations specifiedSuppose there was a large dataset....This SAS macro program splits the dataset by the number of observations mentioned...macro name%split(DatasetName, No ofobservation to split by)/* creating a dataset with 100000 observations*/data dsn;do i=1 to 100000;output;end;run;%macro split(dsn,splitby);data _null_;set &dsn nobs=num;Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-split-dataset-by-number-of.html SAS macro to reorder dataset variables in alphabetic order...How do you reorder variables in a dataset...I get this many a times.... Here's a macro for you to achieve it...For example I've used a dataset sashelp.flags and created some more variables with variety of variables with names upper / lower cases and _'s to demonstrate the reorder macro....   Please try this macro for yourself and let me know your suggestions.... /* Example dataset with variety of variable names */  data flags; set sashelp.flags; a=2; b=4; Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-reorder-dataset-variables.htmlUse SAS function Propcase() to streamline Google ContactsYou might think I am crazy...but I have been using this macro for a long time to fix some contacts in my Google Contacts...I get a little irritated when I can't find a particular person by email...so I wrote this macro...This macro takes for Input a .csv file that is exported from Google Contacts and outputs a file that is ready to be imported to Google Contacts....often I wanted to have Names in the proper case...Try it yourself and let me know if it needs any tweaks...Propcase in SAS Documentation.%macro organizeGoogleContacts(infile,outfile);/*Import your contacts into SAS */ data googlegroups;infile \" &infile\" dlm=',' dsd lrecl=32767 firstobs=2;Read more @ http://sastechies.blogspot.com/2009/11/use-sas-function-propcase-to-streamline.html SAS Macro to Create a delimited text file from a SAS dataset...A document that discusses SAS Macro to Create a delimited text file from a SAS data set.. options mprint; data one;  input id name :$20. amount ;  date=today();  format amount dollar10.2            date mmddyy10.;  label id=\" Customer ID Number\" ;datalines;1 Grant   57.232 Michael 45.683 Tammy   53.21;Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-create-delimited-text-file.html SAS Macro to split a dataset into multiple datasets vertically with a common primary keyThis macro splits a dataset to multiple datasets vertically with a common primary key. For eg, a dataset has 400 fields and 20,000 records. If we can split the dataset into two, with 200 fields and 20,000 records in each dataset with a common field like loan number as primary key would be helpful to load the details for analysis. /**To be called like this...%splitdsnverticallykey(dsn,varperdsn,keyvars=);eg. %splitdsnverticallykey(sashelp.vtable,4,keyvars=memname libname); Where ----------- dsn - libname.datasetname to be splitvarperdsn - How many vars per dsn excluding the key variableskeyvars - specify the primary key variables*/ Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-to-split-dataset-into.html SAS Macro that reads the filenames available at a particular directory on any FTP server (i.e. Windows Network Drive/Unix/Mainframe)Here's a macro that reads the filenames available at a particular directory on any FTP server (i.e. Windows Network Drive/Unix/Mainframe)...For Windows network drives we use the Filename Pipe StatementFor Mainframe and Unix we use the FileName FTP protocol statement.For further reference please refer to Filename statements in SAS Documentation.First we need to create 2 Excel files ServerList.xls – 3 columns with servertype | host | sourcedirRead more @ http://sastechies.blogspot.com/2009/11/sas-macro-that-lists-files-at.html