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

data staff;

JobCategory='FA';

JobLevel='1';

JobCategory=JobCategory||JobLevel;

run;

 

Q: What is the value of the variable JOBCATEGORY in the output data set?

Ans: FA

 

My question is , why not FA1. it did not use the below condition like

JobCategory=JobCategory||JobLevel;

 

please help me to understand this

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

The variable JobCategory has a length of only two characters when defined by this statement:

JobCategory='FA';

So it doesn't matter what you try to concatenate on the end because it will always be truncated back to two characters dropping anything beyond that.

View solution in original post

17 REPLIES 17
SASKiwi
PROC Star

The variable JobCategory has a length of only two characters when defined by this statement:

JobCategory='FA';

So it doesn't matter what you try to concatenate on the end because it will always be truncated back to two characters dropping anything beyond that.

souji
Obsidian | Level 7

data Passengers;

if OrigPassengers=. then

OrigPassengers=100;

TransPassengers=100;

OrigPassengers=.;

NonPaying=10;

 

TotalPassengers=OrigPassengers+TransPassengers;

run;

 

please make me understand this, why the TotalPassengers is missing numeric value in the output

ed_sas_member
Meteorite | Level 14

Hi @souji 

 

In you data step, OrigPassengers is a numeric variable (by default, its length is 8).

It is first set to a missing value (.), then to 100 and then to a missing value.

So a the end, when you compute TotalPassengers = OrigPassengers+TransPassengers, you compute  TotalPassengers = . + 100

-> SAS can't add a missing value to 100, so the result is a missing value.

 

Best,

 

souji
Obsidian | Level 7
Thank You for the clear explanation
ed_sas_member
Meteorite | Level 14
you're welcome !
souji
Obsidian | Level 7

Can you make me understand this as well please, and what would be the results , here they said 110

 

data Passengers;

if OrigPassengers= then

OrigPassengers=100;

TransPassengers=100;

OrigPassengers=.;

NonPaying=10;

 

TotalPassengers= sum (OrigPassengers,TransPassengers );

run;

ed_sas_member
Meteorite | Level 14

Hi @souji 

 

I believe you mean:

 

data Passengers;

if OrigPassengers = . then

OrigPassengers=100;

TransPassengers=100;

OrigPassengers=.;

NonPaying=10;

 

TotalPassengers= sum (OrigPassengers,TransPassengers);

run;

 

-> in this case, TotalPassengers= sum (OrigPassengers,TransPassengers) will be equivalent to TotalPassengers= sum (.,100).

The result will be 100, because the SUM() function returns the sum of the nonmissing values.

 

Best,

souji
Obsidian | Level 7

thank you very muchSmiley Happy

novinosrin
Tourmaline | Level 20

Hi @souji 

 

That's because the intial assignment of JobCategory='FA' assigns a length of 2 bytes and so the concatenated value is truncated to 2 bytes in the output.

 

To verify, 

 

proc contents data=staff;
run;

# Variable Type Len

1 JobCategory Char 2
2 JobLevel Char 1

souji
Obsidian | Level 7

thank you very much

ghosh
Barite | Level 11

That's because the length is set too 2.  Use a length statement first to assign the variable more space

aroop.png

 

souji
Obsidian | Level 7

it work like this if

 

data staff;

length JobCategory $4;

JobCategory='FA';

JobLevel='1';

Job=JobCategory||JobLevel;       /* if I add new variable like Job, then I am getting Job variable value FA1 */

run;

 

****************

if I give JobCategory=JobCategory||JobLevel; with  length statement , it is not given the JobCategory value  FA1, it is only FA

souji
Obsidian | Level 7
Thank You for explanation
souji
Obsidian | Level 7

Thank You very much

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
  • 17 replies
  • 1264 views
  • 1 like
  • 5 in conversation