Wednesday, March 18, 2015

SAS Macro to Import CSV Files into SAS


/***********************************************************
IMPORT CSV files into SAS Work Library
June 10, 2011
http://sastipsbyhal.blogspot.com/
*/
%LET file1 = myFirstFile.csv;
%LET file2 = mySecondFile.csv;
%LET file3 = myThirdFile.csv;
%LET file4 = myFourthFile.csv;
%LET file5 = myFifthFile.csv;
%LET file6 = mySixthFile.csv;
%LET file7 = mySeventhFile.csv;
%LET file8 = myEighthFile.csv;
%LET fileName1 = sasNameFor_myFirstFile;
%LET fileName2 = sasNameFor_mySecondFile;
%LET fileName3 = sasNameFor_myThirdFile;
%LET fileName4 = sasNameFor_myFourthFile;
%LET fileName5 = sasNameFor_myFifthFile;
%LET fileName6 = sasNameFor_MySixthFile;
%LET fileName7 = sasNameFor_mySeventhFile;
%LET fileName8 = sasNameFor_myEighthFile;
%LET fileLoc = \\folder\where\csv\files\are\located\;
%LET fileMax = 8;
%MACRO csvIMPORT;
%Do i = 1 %to &fileMax. ;
PROC IMPORT OUT=WORK.&&fileName&i 
            DATAFILE= "&fileLoc&&file&i"
            DBMS=CSV REPLACE;
    GETNAMES=YES;
    DATAROW=2; 
RUN;
%END;
%MEND;
%csvIMPORT;

Tuesday, March 17, 2015

Need help choosing data visualization colors? Try ColorBrewer2.org

Are you making a data visualization and interested in adding a custom set of colors to make the information really fly off of the page?

If so, I recommend checking out ColorBrewer2.org because it has all sorts of great tools for choosing colors, including color calculators.  It also has tips on choosing color combinations that are color-blind friendly, print friendly, and more.

Thursday, December 4, 2014

My favorite SAS proc: proc freq

No doubt, my favorite proc step is proc freq. It is extremely simple, but therein lies its beauty: it's fast to run and easy to understand. With just two lines of code (almost zero effort), it delivers a set of frequency output for all variables in one printout that anyone can understand, regardless of their involvement with the actual data set. I've found raw proc freq output to be a terrific starting point for conversations on data cleaning or data exploration, no matter who is involved in the conversation:

PROC freq data=NAME;
run;

Tuesday, June 17, 2014

Free SAS Date Calculator

SAS Date Calculator*
Date:

Days since 1/1/1960:


*For valid results, SAS date value must be between 1582 CE and 20,000 CE on the Gregorian Calendar. Note that American Colonies and Great Britain did not adopt the Gregorian Calendar until 1752.

To convert a date in Excel, subtract 21,916:

Free SAS Datetime Calculator

SAS Datetime Calculator*
Datetime:

Seconds since midnight 1/1/1960:


*For valid results, SAS date value must be between 1582 CE and 20,000 CE on the Gregorian Calendar. Note that American Colonies and Great Britain did not adopt the Gregorian Calendar until 1752.

To convert a datetime in Excel, subtract 21,916 and multiply by 86,400: