BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Edwinl
Calcite | Level 5

Hi I am new to SAS and encountered the following problem with missing values.

From the example below i didn't understand how you can count the line of data to allocate numerica data for the values. See below

Id

Cholesterol

Age

Gender

Syst1olic

Diastolic

Height

Weight

SES

1

0

53

M

110

65

  1. 64.3
  2. 147.45

2

2

0

48

F

120

72

  1. 69.2
  2. 167.35

1

3

1

53

F

120

90

  1. 70.8

4

4

1

53

120

80

  1. 72.5
  2. 229.21

4

5

0

45

m

118

74

  1. 66.1
  2. 134.96

3

@1 ID  @3 cholest @5 age @8 gender @10 s ystolic @14  diastolic @17  height @22 weight  @29 SES

How to you count the line of data to get  ID=3 , cholest=5,  age=8, gender=8 and etc.

Any help please

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  I believe that you would be better served by asking your professor or teaching assistant to explain what the "counting along a line of data means". However, in the meantime, consider if you had a piece of graph paper and that every character and space took up one square of the graph paper. This is how SAS reads your "raw data" file, as though every character is in 1 square in a piece of hypothetical graph paper.


consider the following data:

1 0 42 m 110 65 64.3 147.45 2

2 0 53 f 130 72 69.2 167.35 1

And, notice how everything "lines up" (if you look at it in Notepad, displayed with a "fixed pitch" font like Courier). Every character takes 1 "position" or character position or column in the text file. Now, lets put a "counter" or "ruler" above this data:

.........1.........2........2

12345678901234567890123456789 <-- "invisible ruler" where every character is a "column"

-----------------------------

1 0 42 m 110 65 64.3 147.45 2

2 0 53 f 130 72 69.2 167.35 1

The "ruler" starts above the line of dashes and your data is below. ID starts in column 1; the m or f is in column 8; the systolic value starts in column 10 and the diastolic value starts in column 14. You can see how the 110 lines up underneath columns 10, 11 and 12 and how 65 lines up underneath columns 14 and 15. If you place your cursor in position 1 (immediately under the 1 on the ruler), and then move the right arrow cursor key, you can "count" out loud every time the cursor moves one position to the right. In the attached screen shots, I show the "fat" cursor positioned on character 1, on character 8 and on character 14.

When you are reading data with an INPUT statement, if the data are in fixed columns (as your data is in fixed columns), then you use @ pointer control to point to the correct column or "square in the graph paper" to tell SAS where the beginning column is for reading.

Your book gives you the mostly correct INPUT statement for the data, as laid out. It seems to me that the book explains that you will still have problems with the program as written because of the treatment of missing values. So I would expect that when you turn the page, your book will have an explanation of an option that will probably help you read the data as you need to do for your assignment.

It also seems to me that your book is stepping you through the process of writing your program using a trial and error basis. But the whole program in your book is built on the premise that you understand how to "count" the characters on each dataline to understand the correct @ pointer to use in the INPUT statement.

Hope this explanation helps you get a bit more understanding what is meant by "counting" across the data line.

cynthia


cursor_on_8.pngcursor_on_14.pngcursor_on_1.png

View solution in original post

5 REPLIES 5
Edwinl
Calcite | Level 5

Sorry if the question wasn't clear.

I attached a document with the question. Basically I couldn't workout the data line count, how do you count, vertical or horizontal.

Scott_Mitchell
Quartz | Level 8

So I gather you are reading the above in from a text file?

Can you go into the text file using notepad and copy the text into a post?

Is this what you are trying to have returned in your output? ID=3 , cholest=5,  age=8, gender=8.


I am a little lost on what you want.

Cynthia_sas
SAS Super FREQ

Hi:

  I believe that you would be better served by asking your professor or teaching assistant to explain what the "counting along a line of data means". However, in the meantime, consider if you had a piece of graph paper and that every character and space took up one square of the graph paper. This is how SAS reads your "raw data" file, as though every character is in 1 square in a piece of hypothetical graph paper.


consider the following data:

1 0 42 m 110 65 64.3 147.45 2

2 0 53 f 130 72 69.2 167.35 1

And, notice how everything "lines up" (if you look at it in Notepad, displayed with a "fixed pitch" font like Courier). Every character takes 1 "position" or character position or column in the text file. Now, lets put a "counter" or "ruler" above this data:

.........1.........2........2

12345678901234567890123456789 <-- "invisible ruler" where every character is a "column"

-----------------------------

1 0 42 m 110 65 64.3 147.45 2

2 0 53 f 130 72 69.2 167.35 1

The "ruler" starts above the line of dashes and your data is below. ID starts in column 1; the m or f is in column 8; the systolic value starts in column 10 and the diastolic value starts in column 14. You can see how the 110 lines up underneath columns 10, 11 and 12 and how 65 lines up underneath columns 14 and 15. If you place your cursor in position 1 (immediately under the 1 on the ruler), and then move the right arrow cursor key, you can "count" out loud every time the cursor moves one position to the right. In the attached screen shots, I show the "fat" cursor positioned on character 1, on character 8 and on character 14.

When you are reading data with an INPUT statement, if the data are in fixed columns (as your data is in fixed columns), then you use @ pointer control to point to the correct column or "square in the graph paper" to tell SAS where the beginning column is for reading.

Your book gives you the mostly correct INPUT statement for the data, as laid out. It seems to me that the book explains that you will still have problems with the program as written because of the treatment of missing values. So I would expect that when you turn the page, your book will have an explanation of an option that will probably help you read the data as you need to do for your assignment.

It also seems to me that your book is stepping you through the process of writing your program using a trial and error basis. But the whole program in your book is built on the premise that you understand how to "count" the characters on each dataline to understand the correct @ pointer to use in the INPUT statement.

Hope this explanation helps you get a bit more understanding what is meant by "counting" across the data line.

cynthia


cursor_on_8.pngcursor_on_14.pngcursor_on_1.png
Edwinl
Calcite | Level 5

Thanks Cynthia

your explanation was very clear and very helpful

Thank you

Eddie

galeej
Calcite | Level 5

Did you try using the MISSOVER option?

http://www2.sas.com/proceedings/sugi26/p009-26.pdf

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1145 views
  • 0 likes
  • 4 in conversation