BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

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;
Ronein
Onyx | Level 15

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 

 

 

PeterClemmensen
Tourmaline | Level 20

You are correct.

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 803 views
  • 1 like
  • 2 in conversation