I am trying to concatenate some variables in SAS Enterprise guide.
I start with a SAS_table
, which looks something like (note the empty column plums
and the empty observation for pears
:
id farm apples pears cherries plums
1 'Munich' 'Granny' 'Williams' 'RedDelight'
2 'Amsterdam' 'PinkLady' 'Scrumptious
3 'Moscow' 'Braeburn' 'Williams' 'RedDelight'
Then I create global variables as follows:
%do i = 1 %to 3;
%global farm_&i., apples_&i., pears_&i., cherries_&i., plums_&i.;
%end;
And I store the above table in the global variables as follows:
data _NULL_;
set SAS_table;
%do i = 1 %to 3;
if id = &i. then do;
call symput("farm_&i.", farm);
call symput("apples_&i.", apples);
call symput("pears_&i.", pears);
call symput("cherries_&i.", cherries);
call symput("plums_&i.", plums);
end;
%end;
run;
All of the above seems to work smoothly. In a next step I want to the individual variables to get the following output (please note that empty values are just skipped - no extra delimiter (" :: ") is set for these cases):
concat_1: Munich :: Granny :: Williams :: RedDelight
concat_2: Amsterdam :: PinkLady :: Scrumptious
concat_3: Moscow :: Braeburn :: Williams :: RedDelight
To do this, I use the following code:
data _NULL_;
%do i = 1 %to 3;
call_symput("concat_&i",catx(" :: ", &&farm_&i., &&apples_&i.., &&pears_&i..,
&&cherries_&i.., &&plums_&i..));
%end;
run;
However, when I run this code I get the error:
ERROR 159-185: Null parameters for CATX are invalid.
My assumption here is that SAS is unhappy because some of the variables can be empty values. But how do I fix this? I've messed around loads and just can't seem to find a good answer.
catx('::', of farms--plums);
works for me, but enclosing the variables didn't end up working. This works as a quick fix though, so thanks :-) – MRR