Posts

Write a Letter using SAS/ Emailing with SAS

SAS can do many things which most of us don’t have a clue. Here is one example…. Writing a letter: filename formltr ' C:\Documents and Settings\sreddy\Desktop\formltr.rtf ' ; data address; infile datalines; input @ 1 stno  @ 6 lane $12. @ 19 aptno $7. @ 27 city $9. @ 37 state $2. @ 40 zip ; datalines ; 2550 Augusta Blvd Apt#203 Fairfield OH 45014 ; run ; data _null_; retain lm 5; set address; file formltr;* print notitles; put _page_; adr1 = trim(stno) ' ' trim(lane); put @lm adr1; adr2 = trim(aptno); put @lm adr2; adr3 = trim(city) ||', '|| trim(state) ||' '|| trim(zip); put @lm adr3; adr4 = trim('Dear')|| ' ' ||trim('SAS') || ' ' || trim('Users,'); put / @lm adr4; put / @lm ' StudySAS Blog offers a lot of information regarding tips and tutorials on various topics ' ; put @lm ' in SAS. It covers basics to get started to more in-depth topics like Mac...

Special Missing Values in SAS

Image
Definition: Special missing value is a type of numeric missing value that enables you to represent different categories of missing data by using the letters A-Z or an underscore. Ref: SAS 9.1.3 language reference: concepts page no: 102 The symbol usually used to represent a missing value for a numerical variable is the period or dot. Aside from the dot, there are 27 special missing values SAS can store in numerical variables. They are the dot-underscore (._), and dot-letter (.A thru .Z). Note that these special values are case insensitive. That is, .A=.a .B=.b .C=.c etc . If you do not begin a special numeric missing value with a period, SAS identifies it as a variable name. Therefore, to use a special numeric missing value in a SAS expression or assignment statement, you must begin the value with a period, followed by the letter or underscore, as in the following example: x= .d ; When SAS prints a special missing value, it prints only the letter. When data values contain character...

How to create a macro variable containing a list of variables in a DATA set

Sometimes it is very handy to have a macro variable contanining the variables names of the dataset. Here are the 2 different ways you can create a macro variable with list of variables names ... *Method1: Using Proc Contents and Proc SQL; proc contents data =sashelp.class out =class; run ; proc sql noprint ; select distinct (name) into :vars separated by " " from class; quit ; %put &vars; *Method2: Using SASHELP tables and Proc SQL; data class; set sashelp.vcolumn(where=(libname= "SASHELP" and memname= "CLASS" )); keep name; run ; proc sql noprint ; select distinct (name) into :vars separated by " " from class; quit; %put &vars;

PRXMATCH Function

Image
Prxmatch () function is very useful in locating the matching strings. P rxmatch() function has 2 parameters, the first parameter is the regular expression ID (i.e what you are looking in a string for a match) and the second parameter is the character string to be searched. PRXMATCH () function returns the start position of the matching string. Syntax: PRXMATCH (perl-regular-expression, source); Even though PRXMATCH function can be used when.... 1) When you want to identify if there is alphanumeric (has any letter from A to Z) in a variable. 2) If you need to search a character variable for multiple different substrings. Here is how PRXMATCH works in the Ist case. *Prxmatch () function is very useful in locating the matching strings; DATA finda2z; INPUT ID $ 1-3 string $ 5-10; prxmatch= prxmatch (" /[a-zA-Z]/ ",string); DATALINES; 001 ACBED 002 11 003 12 004 zx 005 11 2c 006 abc123 ; run ; proc print; run; Output: *Here PRXMATCH func...

$UPCASEw. format

We all know the importance of UPCASE function in handling the character case strings. But do you know that a format can let you do the same as the UPCASE function (upcasing the variables). $UPCASEw . format works similar to the UPCASE Function. It also does one more thing which UPCASE function doesn’t. i.e: $UPCASEw . format let you apply length to the variable. Remember that w specifies the width of the output field. Example: *********************************************************; data new; *convert it to uppercase; name=" studysas blog "; format name $upcase .; newname=put(name, $upcase32 .); *Put function let you apply $upcase format; run; **********************************************; *The length of the new variable newname will be 32.

SAS Supplied Formats for SAS date 17750

Image

Replace Missing Numeric Values using Missing Option/Proc STDIZE

Image
MISSING OPTION Replacing missing values with the desired value like a zero is always a challenge, especially when we have a dataset with a number of columns to standardize. The OLD WAY of doing it to write a DATA step code with  if……then statements like...   if var=. then var =0; t o make 0 appear instead of . (dot) in the tables output. With the SAS option called missing you can save a lot of typing.  If you place the following SAS option code before the generation of the table output: Option missing=" 0 "; SAS will display 0 (zero) instead of the . (dot) on the table. In fact it can display whatever the character we would like to display for missing values.  You can use a - (line) or * (star). Always change it back the option missing setting to default as  Option Missing='';   otherwise you may endup getting unexpected results; Warning : Since we are using this option to display zeros instead of .(dots), you sh...