- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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,
- Tags:
- sum()
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you very much![]()
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you very much
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That's because the length is set too 2. Use a length statement first to assign the variable more space
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank You very much