Reading Raw Data in SAS (Part I)

Delwiche, Lora D., and Susan J. Slaughter. The Little SAS Book: A Primer, 5th Edition [Chapter 2.5-2.7]

Reading Raw Data Arranged in Columns

Use column input if each of the variable’s values is found in the same place in the data line, and all the values are character or standard numeric, which contains only numerals, decimal points, plus and minus signs, and E for scientific notation, so anytime you have non-standard data, informants become handy. A good example of column input is survey data, which are often coded into single digits (0-9). The advantages of column input over list input include:

  • spaces are not required between values
  • missing values can be left blank
  • character data can have embedded spaces
  • you can skip unwanted variables

How does it work?

After the INPUT keyword, list the first variable’s name. If the variable is character, leave a space; then place a $. If the variable name is numeric, leave a space. Then list the column or range of columns for that variable.

INPUT Name $ 1-10 Age 11-13 Height 14-18;

Note: the columns are positions of the characters or numbers in the data line, NOT columns like those you see in a spreadsheet. <— I was very confused about this in the beginning, so be aware.

Reading Raw Data Not in Standard Format

Again, standard numeric data contains only numerals, decimal points, plus and minus signs, and E for scientific notation, so anytime you have non-standard data, informants become handy.

The most common non-standard data is dates. Using date informats, SAS will convert conventional forms of dates into a number, the number of days since January 1, 1960. Don’t ask me why January 1, 1960, please. The author of the book didn’t know either.

There are 3 general types of informats: character, numeric, and date.

Character $informatw. 
Numeric informatw.d 
Date informatw.

$ indicates character informats, informat is the name of the informat, is the total width, and is the number of decimal places. The period is very important as well. Without a period, SAS may try to interpret the informat as a variable name, which by default, cannot contain any special characters except the underscore.

Example: Pumpkin-Carving Contest
name, age, type (carved or decorated), date entered, scores
Alicia Grossman  13 c 10-28-2012 7.8 6.5 7.2 8.0 7.9
Matthew Lee       9 D 10-30-2012 6.5 5.9 6.8 6.0 8.1
Elizabeth Garcia 10 C 10-29-2012 8.9 7.9 8.5 9.0 8.8
Lori Newcombe     6 D 10-30-2012 6.7 5.6 4.9 5.2 6.1
Jose Martinez     7 d 10-31-2012 8.9 9.510.0 9.7 9.0
Brian Williams   11 C 10-29-2012 7.8 8.4 8.5 7.9 8.0
* Create a SAS data set named contest;
* Read the file Pumpkin.dat using formatted input;
DATA contest;
   INFILE 'C:\MyRawData\Pumpkin.dat';
   INPUT Name $16. Age 3. +1 Type $1. +1 Date MMDDYY10. 
         (Score1 Score2 Score3 Score4 Score5) (4.1);
* Print the data set to make sure the file was read correctly;
PROC PRINT DATA = contest;
    TITLE 'Pumpkin Carving Contest';

The variable Name has an informat of $16., meaning that it is a character variable 16 columns wide. Variable Age has an informal of 3, is numeric, three columns wide, and has no decimal places. Variable Date has an informat MMDDYY10. and reads dates in the form of MM-DD-YYY or MM/DD/YYYY, each 10 columns wide. The remaining variable, Score1 through Score5, all require the same informal, 4.1. By putting the variables and the informat in separate sets of parentheses, you only have to list the informat once.

Want to see the results of the PRINT procedure? Why don’t you try it yourself. =]

Honestly, if you understand 2.7 Reading Raw Data Not in Standard Format, 2.5 and 2.6 are very easy to comprehend, because reading data not in standard format is built upon reading data separated by spaces and arranged in columns. I will move on with my study. However, if you are curious to know what is covered in 2.5, but are too lazy to read the book, please comment below so we can have a thorough discussion on how to read raw data in SAS.

My first SAS data chart

This is my very first chart created in SAS with codes. The entire coding process was simple and quick, but when I saw this clean, neat raw data chart, I was still filled with joy and excitement. Perhaps such rewarding results are the reasons why some programmers enjoy programming.

I will continue reading The Little SAS Book and studying this system. Please look forward to more examples it offers at this little corner of the world. :]

Flowers on an autumn Saturday

I recently started to think about how to utilize my phone to capture the beauty of this world, this wonderful, amazing space God has created for each individual to live in and enjoy.

You can see this world through a different pair of eyes … called lens.

Sometimes, if you see from a different angle, a discourage can turn into an encouragement; a hurt can turn into a comfort; and beautiful triplets can be even more astonishing: perfectly blended into the background.

This is what comes next: a flower recipe, for me, an amateur cook and a flower lover. Please look forward to more pictures at this little corner of the world. :]


how would you define selfish?

When people call someone bold and straightforward, does that imply that he or she is in fact selfish? Is someone who is easily tempered selfish deep deep inside? Is it because Hitler is selfish instead of merciless that millions of Jews were killed? 

If you think about it, you know I am also a selfish person. That is why I get irritated easily. But because I am a Christian, I know it is not holy, not Christ-like to be selfish; thus, I cry when I am frustrated with my temper, hoping it will wash away my shame. 
God, help me.

3 West (Continued)

Many things have happened this the morning.

An old, VIP patient fell and hurt his knee, so the chief nurse had to call and comfort his wife, who I believe must had paniced and been anxious. It is often seen in the hospitals that old couples hold each other’s hand and support each other whenever they can. Even the ones that are not spending much can time together during the day, I can tell that they got married because they were in love and they probably have been loving each other.

And then, during my break, I was reading this novel about an old man walking, literally walking, to see his old female friend who he had lost contact with but suddenly heard from. In the sections I was reading today, there are detailed descriptions of his psychological changes as well as those of his wife’s, who stays at home as her husband progresses towards the destination. Over twenty-some years, their daily conversations have been minimized to simple greetings and superficial responses. However what they do not realize is that after these many years, they still love each other yet they don’t know it.

Somehow, I started to miss him. I also thought about my parents. And then myself. Life is so unpredictable, but if I read this book before mom was sick, if I shared this book with her before or while she was sick, and if she actually read it and thought about it, would anything change? Would she realize something that had been hiding from her during the years of marriage? How much I wish she was here with me.

A small but very interesting finding: the facial tissue can signal! The color of the last a few pieces is different from while, so people know when to refill, replace or make new purchases. Isn’t that cool?  

3 West

Patients walk in the aisle between breakfast and lunch hours. Because 3W was built as a loop, I see walking patients several times during the morning. Sometimes the patient walks with the accompany of his or her spouse; most of the time they walk alone.

The lady that resides in room 72 has high fall risk, very common. She doesn’t press any button or make any calls to inform anyone she needs help. Instead, she yells “I need help! Help! Someone help me!” The voice can pass through the heavy wooden door and be heard by the HUSC who sits right in front of 72. Nurses can’t do anything about it.

I feel sorry about this lady living in 72. She reminds me of my mom, who was so helpless and hopeless perhaps, yet still wishing someone could take away the pain. I don’t want to be sick, and I don’t like feeling hopeless. What a blessing it is for people to have their spouse or families with them when they get old.

No? Yes? No?

He is probably the first boy who told me that he liked me but didn’t know why. He is perhaps the first one who told me to just be myself. What he said means a lot to me.

Nonetheless, he is not a Christian; he is not older than me; he is not much taller than me; he is not a Chinese; he does not know Chinese culture… There are many things I value but he is not familiar with. Of course, there are also many things I don’t care but mean much to him.

If I know what is right and what is wrong, I will know the answer to that question. If I don’t know, I should pray and wait for His answer. What if God doesn’t respond to my prayer or He answered but I refuse to listen?

All these things trouble me, day and night. What should I do? What should I not do?