BookmarkSubscribeRSS Feed
5 REPLIES 5
PaigeMiller
Diamond | Level 26

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
Nipun22
Fluorite | Level 6
suppose there's a single space. then?
PaigeMiller
Diamond | Level 26

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
Tom
Super User Tom
Super User

@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.

ballardw
Super User

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:

Nipun22_0-1718368501256.png

 


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 336 views
  • 3 likes
  • 4 in conversation