General: Markdown Post Testing

MarkDown Quick Reference

Head 2

Head 3

italic
italic
bold
bold

list: (not working)

  • Item 1
  • Item 2

List: (works)

  • Item 3
  • Item 3a
  • Item 3b

List: (not working)

  1. Item 1
  2. Item 2
  3. Item 3

List: (works)

  • Item 3a
  • Item 3b

End a line with two or more spaces to create line breaks. Second line. (ONLY WORK IN R MARKDOWN. DON’T WORK FOR WORDPRESS MARK DOWN).

Horizontal Rule:


Links:
WordPress

Quotes: (indented quotes not working)

Quotes someone.

>      Quote details.

  • Quote with bullet

       Quotes

Code:
one line of code

Code Block:

[code lang=text]
This is a section of
programing
in a block fashion.
Enclosed by ~.
[/code]

[code lang=text]
This is another section of
programing
in a block fashion.
Enclosed by `.
[/code]

Tables:

First Header Second Header
Don’t have to be the same width as the header. Markdown will wrap the text for you.
Definition List:
Markdown
Text-to-HTML conversion tool

Source: Markdown Quick Reference

Reading Data from fixed position txt file

Read data from fixed position txt file to SAS.

This type of file normally don’t have the variable name as the first observation because the length of the variable name might not be consistent with the length of the variable. The starting position for each variable is the same for all the records in the txt file.

Below in the admit table in fixed position txt file.

2458 Murray, W      M 27 1  72 168 HIGH 85.20
2462 Almers, C      F 34 .  66 152 HIGH 124.80
2501 Bonaventure, T F 31 .  61 123 LOW  149.75
2523 Johnson, R     M 43 31 63 137 MOD  149.75
2539 LaMance, K     M 51 4  71 158 LOW  124.80
2544 Jones, M       M 29 6  76 193 HIGH 124.80
  • Require . for missing value
  • use $ in input statement to identify character variable
  • use X-X to identify the starting position and ending position for the character variables.  This also determines the length of the character variable.
  • use @x to identify the starting position for the numeric variable.
  • use x. to identify the length of the numeric variable. eg: @23 age 2. indicates to read from position 23 the age variable with a length of 2.

Method1:  not identify the position for the numeric variable.

data admit;
infile 'C:\Users\irisan\Documents\My SAS Files(32)\9.3\Tutorial\admit_fixed.txt' ;
input ID $ 1-4 name $ 6-19 sex $ 21 age date height weight actlevel $ 36-39 fee;
run;

Method2: identify the position for each variable.

data admit;
infile 'C:\Users\irisan\Documents\My SAS Files(32)\9.3\Tutorial\admit_fixed.txt' ;
input
ID $ 1-4
name $ 6-19
sex $ 21
@23 age 2.  /* length for age is 2 */
@26 date 
@29 height
@32 weight
actlevel $ 36-39
@41 fee ;
run;

Read only  certain observations that meet the criteria for selected variables from the txt file, using 2 input statements and if statement.  Second input statement only contains the required variables, so not all the variables are read into the target SAS dataset.

data admit;
infile 'C:\Users\irisan\Documents\My SAS Files(32)\9.3\Tutorial\admit_fixed.txt' ;
input actlevel $ 36-39 @23 age  @;
if  age < 35 and actlevel EQ 'HIGH' then delete;
input
name $ 6-19
sex $ 21
@29 height
@32 weight
@41 fee ;
run;

 

SAS: Organizing data through Proc Format

Proc Format can be used to group categorical variables or numeric values for reporting.  The following examples show the coversion of sex, age, and id variables into desired format. Method 1 uses put and input statements and creates new variables, while method 2 use format statement to just format the existing variables.

  • Need $ in the format name for the existing character variable. eg. $gender
  • Need to put . after the format name when applying the format. eg. gender = put(sex, $gender.); format age agerange. sex $gender.;

/**** Proc Format ****/
proc format;
value
$gender
‘M’ = ‘Male’
‘F’ = ‘Female’
;
value
agerange
1 – 30 = ‘le 30’
30<-40 = '31 to 40'
40<-50 = '41 to 50'
50<-60 = '51 to 60'
60<-100 = 'gt 60'
other = 'Missing'
;
run;
options fmtsearch = (work.formats);

Method1:

data admit;
set sasuser.admit;
agecatgory = put(age, agerange.);
gender = put (sex, $gender.);
numericid = input(id, 4.);
run;

Method2:

data admit;
set sasuser.admit;
format age agerange. sex $gender.;
run;

Character to Numeric, using INVALUE.
Example: convert character gpa to numeric gpa.

/*** calculate the ESL grade points that needs to be backed out from the GPA ***/
/** format grade to index **/
proc format ; 
invalue   /* UES INVALUE, NOT VALUE */
$grade
'A+' = 9
'A'= 8
'B+'= 7
'B'= 6
'C+' = 5
'C' = 4
'D+' = 3
'D' = 2
'E' = 1 
'F' = 0
'P' = 0
;
run;
proc options  option=fmtsearch;run;
data backgpa;
set pes;
array crs{3} esl1000 esl1010 esl1015  ;
array ncr{3} esl1000ncr esl1010ncr esl1015ncr  ;
array cr{3} esl1000cr esl1010cr esl1015cr  ;
array back{3} esl1000bo esl1010bo esl1015bo;
do i =1 to dim(crs);
if crs{i} ne '' and ncr{i} ne 'NCR' then  back{i} =  input(crs{i}, $Grade.) * input(cr{i}, 8.);
end;
drop course1-course20 gr1-gr20 credit1-credit20 ncr1-ncr20 i;
run;

SAS: Reading Data from tab delimited txt file

Read tab delimited txt file to sas.

data admit;
length name $14.;
infile ‘C:\Users\Documents\My SAS Files(32)\9.3\Tutorial\admit.txt’ dlm=’09’x firstobs =2  ;
input ID $4. name $ sex $1. age date height weight actlevel $4. fee;
run;

  • missing value in the txt file should be either . or blank space.
  • use dlm=’09’x to read the tab delimited file
  • SAS default character variable length is 8. In order to read the name variable, need to add length statement before the infile statement, otherwise the name field will be truncated at 8.
  • add firstobs =2 if the first line in the txt file is the variable names.
  • use lrecl= 32760 if the observation is very long (longer than the default 256).

Read only certain observations that meet the criteria from the tab delimited file to sas.

Method1:

data admit;
length name $14.;
infile 'C:\Users\Documents\My SAS Files(32)\9.3\Tutorial\admit.txt' dlm='09'x firstobs =2;
input ID $4. name $ sex $1. @;
if sex = 'F' then delete;
input age date height weight actlevel $4. fee;
run;

Method2:

data admit;
length name $14.;
infile 'C:\Users\irisan\Documents\My SAS Files(32)\9.3\Tutorial\admit.txt' dlm='09'x firstobs =2;
input ID $4. name $ sex $1. @ ;
if sex = 'M' then do;
input  age date height weight actlevel $4. fee;end;
else delete;
run;
  • use 2 input statements to select ‘M’ admits.
  • in the first input statement, use one trailing @ to tell SAS to hold the record for if statement. In method 1, the ‘F’ records will not be passed on to the second input statement.
  • for tab delimited data, it is not possible to only input selected variables from the source file.  All the variables need to be input in the variable sequence of source file from left to right.