Solved
Contributor
Posts: 27

# Two Questions: One concatenation question and one input question

I hope you are all having a good day. I am currently studying for my Base SAS Certification and I have two questions. My first question deals with concatenation. Why does the code below give a value of "FA" for job category rather than "FA1"?

data jobcat;
jobcategory="FA";
joblevel="1";
jobcategory=jobcategory||joblevel;
run;

For the code below, why do we need "else input"? What exactly is this saying?

Name \$ 1-14 / Address \$ 1-14 / City \$ 1-12;
if City='New York ' then input @1 State \$2.;
else input;
datalines;
Joe Conley
123 Main St.
Janesville
WI
Jane Ngyuen
555 Alpha Ave.
New York
NY
Jennifer Jason
666 Mt. Diablo
Eureka
CA
;
run;

Accepted Solutions
Solution
‎03-16-2017 12:24 PM
PROC Star
Posts: 8,164

## Re: Two Questions: One concatenation question and one input question

The data always has a record for state. The code is written so that it only gets the state if city='New York'.

However, when city isn't 'New York' you would end up reading that record set's state as the next set's name variable and every other set will input the wrong information for each field.

Thus, the record that contains state has to be input, regardless of whether it inputs state or not.

Art, CEO, AnalystFinder.com

All Replies
Super User
Posts: 13,542

## Re: Two Questions: One concatenation question and one input question

Examine the characteristics of the the variable jobcategory (proc contents, column view of data set or any of the other possibilities).

You "assigned" a length of 2 characters with the initial assignment of a value. So there isn't a place to add another character onto the end of the same value.

Consider:

```data work.jobcat;
jobcategory="FA";
joblevel="1";
jobcategory2=jobcategory||joblevel;
run;```

Your second example is incomplete. But basically it conditionally executes one more read looking for a State value only when the City encountered in the previous not-completely shown input encounters City. The "else input" advance the input pointer one row.

Did you run the code without the Else? It becomes very obvious why it is needed if you do and look at the resulting data set.

You would have to ask the code writer why they only want a state value when the city of New York is encountered.

Contributor
Posts: 27

## Re: Two Questions: One concatenation question and one input question

Sorry I'm just getting to this now. Thank you for your answer. I'm still a bit confused on the second question. I thought that the input pointer would advance to the next row regardless of the else input statement. Is there any way you can dumb it down more for me? I did try it without the else input.

Solution
‎03-16-2017 12:24 PM
PROC Star
Posts: 8,164

## Re: Two Questions: One concatenation question and one input question

The data always has a record for state. The code is written so that it only gets the state if city='New York'.

However, when city isn't 'New York' you would end up reading that record set's state as the next set's name variable and every other set will input the wrong information for each field.

Thus, the record that contains state has to be input, regardless of whether it inputs state or not.

Art, CEO, AnalystFinder.com

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
• 3 replies
• 154 views
• 0 likes
• 3 in conversation