1 / 11

Contents

Contents. What are formats? What are informats? Text → Numeric Numeric → Text Formats at run time (putn, putc, inputn, inputc) Format tips. What are formats?. A format is an instruction that SAS uses to write data values. <$> format < w >.< d > Eg. DOLLAR10.2 , DATE 9. , $REVERSw.

lowell
Download Presentation

Contents

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Contents What are formats? What are informats? Text → Numeric Numeric → Text Formats at run time (putn, putc, inputn, inputc) Format tips

  2. What are formats? A format is an instruction that SAS uses to write data values. <$>format<w>.<d> Eg. DOLLAR10.2 , DATE9. , $REVERSw data_null_; AMOUNT = 999.9999; put AMOUNT dollar10.2; run; AMOUNT=$1,000.00

  3. An informat is an instruction that SAS uses to read data values into a variable. <$>informat<w>.<d> Eg. MONYYw. , DATE9. What are informats? data_null_; input AMOUNT COMMA11.; put AMOUNT=; datalines; $1,000,000 ; run; AMOUNT=1000000

  4. Text → Numeric Use a numerical INFORMAT → with the INPUT function. INPUT(source, informat.) source must be character data_null_; NEW_DATE = input("05Nov2006", date9.); NEW_WORD = input("dlroW olleH", $REVERS11.); put NEW_DATE= yymmddn8.; put NEW_WORD= ; run; NEW_DATE=20061105 NEW_WORD=Hello World

  5. Numeric → Text Use a FORMAT → with the PUT function. PUT(source, format.) source can be character or numeric, but format must match. data_null_; TXT_VAR1 = put(12345, z9.); TXT_VAR2 = put(“Harry’s Place”, $QUOTE15.); put TXT_VAR1= ; put TXT_VAR2= ; run; TXT_VAR1=000012345 TXT_VAR="Harry's Place"

  6. Format binding at run time Dynamically assign formats depending on the data. PUTN, PUTC, INPUTN, INPUTC Use formats in macro code procformat; value MYFMT 1 = 'date9.' 2 = 'mmddyy10.'; quit; data_null_; input NUMBER KEY; DATEFMT = put(KEY,WRITFMT.); DATE = putn(NUMBER,DATEFMT); put DATEFMT= DATE=; datalines; 15756 1 14552 2 ; run; DATEFMT=date9. DATE=20FEB2003 DATEFMT=mmddyy10. DATE=11/04/1999 %let MVAR1= "01Jan2006"d; %let MVAR2= %sysfunc(putn(&MVAR,YYMMDDn8.)); %put MVAR2= &MVAR2; MVAR2=20060101

  7. Format tip Change the format used depending on the range Policy Quote Date Cumulative Cumulati POL_QDATE Frequency Percent Frequency Percen ------------------------------------------------------------ 2007 311123 1.44 311123 1.44 2008 5155314 23.85 5466437 25.29 JUL08 1927139 8.92 7393576 34.21 AUG08 1970173 9.12 9363749 43.32 SEP08 2044662 9.46 11408411 52.78 OCT08 1982797 9.17 13391208 61.95 NOV08 1807749 8.36 15198957 70.32 DEC08 1654087 7.65 16853044 77.97 01JAN2009 82170 0.38 16935214 78.35 02JAN2009 135552 0.63 17070766 78.98 03JAN2009 123686 0.57 17194452 79.55 04JAN2009 137235 0.63 17331687 80.19 procformat; value myfmt low - "30jun2008"d = [year4.] "01jul2008"d - "31dec2008"d = [monyy5.] other = [date9.]; run; procfreqdata=ALLMM.AGG_QT_DIMS; format POL_QDATE myfmt.; tables POL_QDATE / list; run;

  8. Format tip Identify missing values procfreqdata=PRVMM.NEWBUS_ALL(OBS=100); tables _numeric_ _character_ / missing; format _numeric_ MISSN. _character_ $MISSC.; run; Car Registration Number Cumulative Cumulative REGNO Frequency Percent Frequency Percent ------------------------------------------------------------ Missing 24 24.00 24 24.00 Present 76 76.00 100 100.00 Super Profile Cumulative Cumulative PCLUS Frequency Percent Frequency Percent ------------------------------------------------------------ Missing 16 16.00 16 16.00 Present 84 84.00 100 100.00

  9. Format tip Produce heat maps, easily. procformat; value HMAP low - .15 = "LIGHTYELLOW" .15 - .25 = "YELLOW" .25 - .30 = "PINK" .30 - .40 = "BLUE" .80 - HIGH = "RED"; quit; procreportdata=UXWORK.&DATA._SUM nowd split="*" ; column ("&SRC_BRAND. - &WHERE - &PLOTVAR"((&YLAB. &YVAR) (&XLAB. &XVAR), &PLOTVAR)); define &YVAR / group' 'order=data; define &XVAR / group' 'order=internal; define &XVAR / group' 'ACROSSorder=internal; define &PLOTVAR / analysis' ' style(column)=[background=HMAP. foreground=HMAPB.]; run;

  10. Quiz

  11. Tie breaker • If a macro variable exists both in the global symbol table and in the local symbol table, can you reference the global value from within the macro that contains the local macro variable? • Yes - global macro values always override local macro values • Yes - SAS always uses the macro value that is defined first • No - SAS finds the local macro first and uses it • No - SAS cannot assign values twice and sets the value to null

More Related