Statistical programming, matrix languages, and more

proc iml issue with concatenation

Accepted Solution Solved
Reply
Contributor
Posts: 39
Accepted Solution

proc iml issue with concatenation

[ Edited ]

I have the following code that perfectly works:

 

proc iml;
a = {1,2,3,4,0};
b = {1 1, 1 2, 2 3,3 1, 2 2};
c = a||b;
d = full(c);
print a,b,c,d;
quit;

Now, I'm trying to the same thing with one row of my data but getting errors. My code is:

 

proc iml;
  use test(keep = TR_:);
  read all var _num_ into x [colname=vn];
  b = t(scan(compress(vn,'S'),2,'t_') // scan(compress(vn,'S'),3,'t_'));
  a = t(x);
  c = a||b;
  d = full(c);
  print x, a, b, c, d;
quit;

I can't somehow get the matrix 'c' correctly, it is throwing some error. Can anyone please point out where I'm going wrong?

 

The test file is following:

YearSegment1TR_S6_S5TR_S7_S5TR_S6_S7TR_S7_S6TR_S7_S8TR_S6_S8TR_S3_S1TR_S2_S1TR_S2_S3TR_S3_S2TR_S3_S4TR_S2_S4TR_S6_S2TR_S7_S3TR_S5_S1TR_S8_S4TR_S2_S6TR_S3_S7
2017ABC0.0010.3000.020000000000000

Accepted Solutions
Solution
‎12-19-2017 06:04 PM
Contributor
Posts: 39

Re: proc iml issue with concatenation

[ Edited ]

Got it. The reason was actually the fact that I didn't do num(scan(compress(vn,'S'),2,'t_')) so b was character matrix in disguise of numeric.

 

Following code works:

 

proc iml;
  use test(keep = TR_:);
  read all var _num_ into x [colname=vn];
  b = t(num(scan(compress(vn,'S'),2,'t_')) // num(scan(compress(vn,'S'),3,'t_')));
  a = t(x);
  c = a||b;
  d = full(c);
  print x, a, b, c, d;
quit;

 

 

View solution in original post


All Replies
Super User
Posts: 11,810

Re: proc iml issue with concatenation

Paste the code and messages from the Log into a code box opened with the forum {I} menu icon.

 

 

 

Solution
‎12-19-2017 06:04 PM
Contributor
Posts: 39

Re: proc iml issue with concatenation

[ Edited ]

Got it. The reason was actually the fact that I didn't do num(scan(compress(vn,'S'),2,'t_')) so b was character matrix in disguise of numeric.

 

Following code works:

 

proc iml;
  use test(keep = TR_:);
  read all var _num_ into x [colname=vn];
  b = t(num(scan(compress(vn,'S'),2,'t_')) // num(scan(compress(vn,'S'),3,'t_')));
  a = t(x);
  c = a||b;
  d = full(c);
  print x, a, b, c, d;
quit;

 

 

PROC Star
Posts: 965

Re: proc iml issue with concatenation

@ss59 glad you found your answer Smiley Happy

 

1 small thing that itches every IML programmer about this code is that you should always remember to close your data sets when you are done reading from them. So add a

 

close test;

statement after your read statement.

 

For a (5) reason(s) why, read Five Reasons to CLOSE Your Data Sets

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 209 views
  • 3 likes
  • 3 in conversation