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.
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.