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
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.
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.
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
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,
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;
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,
thank you very much![]()
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
thank you very much
That's because the length is set too 2. Use a length statement first to assign the variable more space
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
Thank You very much
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.