data staff;
jobcategory='FA';
joblevel='4';
jobacategory=jobcategory||joblevel;
run;
for the code to concatenate two strings jobcategory only outputs 'FA'. if change the code to jobcategory1=jobcategory||joblevel, jobcategory1 will be assigned to 'FA4'.
Why can not assign a new value to the variable of jobcategory through the code above?
Because the first reference to jobcategory is the assignment of the two-character literal value "FA", SAS assigned a length of $2 to the variable. So while the concatenation operator was honored by SAS, it only could fit the first two characters of the result into the variable.
But the new variable jobcategory1 will be assigned a length of $3, since that is the sum of $2 (for jobcategory) and $1 (for joblevel).
BTW, if instead of
jobcategory1=jobcategory||joblevel;
you had used one of the concatenation functions,
jobcategory1=cat(jobcategory,joblevel);
you would get the same resulting values, but SAS would assign a length of $200 to jobcategory.
Because the first reference to jobcategory is the assignment of the two-character literal value "FA", SAS assigned a length of $2 to the variable. So while the concatenation operator was honored by SAS, it only could fit the first two characters of the result into the variable.
But the new variable jobcategory1 will be assigned a length of $3, since that is the sum of $2 (for jobcategory) and $1 (for joblevel).
BTW, if instead of
jobcategory1=jobcategory||joblevel;
you had used one of the concatenation functions,
jobcategory1=cat(jobcategory,joblevel);
you would get the same resulting values, but SAS would assign a length of $200 to jobcategory.
Don't force SAS to guess how you want your variables defined, especially character variables. Tell it explicitly what length to use.
data staff;
length jobcategory $3 joblevel $1 ;
jobcategory='FA';
joblevel='4';
jobacategory=jobcategory||joblevel;
run;
Note that you type 'jobacategory' instead of 'jobcategory'. If jobcategory it is strange that the code still outputs only 'FA'.
data staff;
length jobcategory $3 joblevel $1 ;
jobcategory='FA';
joblevel='4';
jobcategory=jobcategory||joblevel;
run;
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!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.