Hello
I want to concatenate multiple times and I am using array.
In the result data set the new variables have null value. What is the problem with the code?
Data RawTbl;
INFILE DATALINES DLM=',';
input ID Customer1901 $ Branch1901 $ Customer1902 $ Branch1902 $ Customer1903 $ Branch1903 $ Customer1904 $ Branch1904 $;
cards;
3188,22339829,855,22339829,855,22339829,855,22339829,855
3195,40031612,832,40031612,832,40031612,832,40031612,832
;
run;
Data wanted;
set RawTbl;
Array Customer(4) Customer1901 Customer1902 Customer1903 Customer1904;
Array Branch(4) Branch1901 Branch1902 Branch1903 Branch1904;
Array CustBranch(4) CustBranch1901 CustBranch1902 CustBranch1903 CustBranch1904;
Do i=1 to 4;
CustBranch(i)=CATX('-',Customer(i),Branch(i));
end;
Run;
Create your arrays with the proper type and length
Data wanted;
set RawTbl;
Array Customer(4) $ Customer1901 Customer1902 Customer1903 Customer1904;
Array Branch(4) $ Branch1901 Branch1902 Branch1903 Branch1904;
Array CustBranch(4) $ 100 CustBranch1901 CustBranch1902 CustBranch1903 CustBranch1904;
Do i=1 to 4;
CustBranch(i)=CATX('-',Customer(i),Branch(i));
end;
Run;
Create your arrays with the proper type and length
Data wanted;
set RawTbl;
Array Customer(4) $ Customer1901 Customer1902 Customer1903 Customer1904;
Array Branch(4) $ Branch1901 Branch1902 Branch1903 Branch1904;
Array CustBranch(4) $ 100 CustBranch1901 CustBranch1902 CustBranch1903 CustBranch1904;
Do i=1 to 4;
CustBranch(i)=CATX('-',Customer(i),Branch(i));
end;
Run;
As I see there were 2 problems in the array that I defined:
1- I didn't use $ sign to tell that the variables are chars
2- I didn't use 100 in length
You are correct.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.