Obsidian | Level 7

what's the correct option and why?

5 REPLIES 5
Diamond | Level 26

Re: what's the correct option and why?

No way of knowing when you present text as a screen capture, and the original was a proportional font, so we can't even tell how many spaces are in the data between 24613 and \$25.31.

I'd move on to another question.

--
Paige Miller
Obsidian | Level 7

Re: what's the correct option and why?

suppose there's a single space. then?
Diamond | Level 26

Re: what's the correct option and why?

It is pointless to conjecture what the answer is, since there is a high probability that there are more spaces and we don't know how many. I would move on to another question (or find this question on the internet with non-proportional fonts that we can tell how many spaces there are).

--
Paige Miller
Super User

Re: what's the correct option and why?

@Nipun22 wrote:
suppose there's a single space. then?

If the goal here is to learn then you can use the example to explore such questions.

Try it with different numbers of spaces and see what happens when you run it.

Make sure you understand why you are getting the results you get in each situation.

Super User

Re: what's the correct option and why?

Here is an example that reads that data with different number of spaces between the first and second entry

And this is why you have comments about PICTURES of code/data and why it is important.

data example;
input idnum 5. @10 price;
datalines;
24613 \$25.31    <this line has \$ at column 7
24613  \$25.31    <this line has \$ at column 8
24613   \$25.31    <this line has \$ at column 9
24613    \$25.31    <this line has \$ at column 10
24613     \$25.31    <this line has \$ at column 11
;

The one with the \$ at column 9 is the only one that returns 25.31

others either read starting in the middle of the second value OR run into an incorrect informat as to read a value containing \$ you need the COMMA or DOLLAR informat. Which is why the last lines of data get missing values for the Price.

Do you know what the @10 means? That tells SAS to move the input (or output on a PUT statement) pointer to column 10.

Since there is no DOLLAR Format assigned to the variable price it would never show \$25.31 as a result.

And pasting the exact same code into the message window instead of a text box opened using the </> icon that appears above the message window illustrates why we want code pasted into a text or code box: the forum software will reformat text pasted into the message windows, i.e. change what you have.

data example;
input idnum 5. @10 price;
datalines;
24613 \$25.31 <this line has \$ at column 7
24613 \$25.31 <this line has \$ at column 8
24613 \$25.31 <this line has \$ at column 9
24613 \$25.31 <this line has \$ at column 10
24613 \$25.31 <this line has \$ at column 11
;

And a different related example:

data example2;
input idnum 5.  price comma6.;
datalines;
24613\$25.31
24613 \$25.31
24613  \$25.31
2461\$25.31
2461 \$25.31
2461 \$123.456 ;

When you can answer these questions you will have learned a bit more:

1) Why is idnum missing when reading the 4th row?

2) Why is there no problem reading row 1?

3) Why is the value of price on row 2 different than row 1?

4) Why is the value of price on row 3 different than row 2?

5) Why is the value of price on row 4 the same as for row 5 and row 1?

6) Why is the value of price on the last row 123.4?

Hint: Columns are important and knowing which is used when.

Strong suggestion: stop using sites that present code in proportional fonts. Or retype the stuff into your editor as my example above and prepare to test variations. Note: copying text from websites, PDF or word processor documents can also introduce artifacts such as non-printable characters that can keep code from, some characters get switched to document characters such as - getting replaced with an emdash that looks similar but is not something a programming compiler/interpreter uses. Quotes that should be  ' or '  may be "smart quotes" or a different character.

@Nipun22 wrote:

Discussion stats
• 5 replies
• 628 views
• 3 likes
• 4 in conversation