Sas Macro Examples

  • Uploaded by: SASTechies
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sas Macro Examples as PDF for free.

More details

  • Words: 755
  • Pages: 9
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 specified Suppose 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.html

Use SAS function Propcase() to streamline Google Contacts You 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.23 2 Michael 45.68 3 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 key This 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 split varperdsn - How many vars per dsn excluding the key variables keyvars - 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 Statement For 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 | sourcedir

Read more @ http://sastechies.blogspot.com/2009/11/sas-macro-that-lists-files-at.html

Related Documents

Sas Macro Examples
June 2020 8
Sas
April 2020 20
Sas
June 2020 17
Sas
November 2019 31
Sas
November 2019 32

More Documents from ""