Help using Base SAS procedures

SAS array

Reply
New Contributor
Posts: 2

SAS array

Hi,

I run into something interesting. I have a data set as
qid a b c
DP005205 0.49 -2 0.019
DP005206 0.934 -1.793 0.095
DP005207 0.888 -0.073 0.024.

Then in order to use them in another data set, I put the three records into one record data set as
qqid1 qqid2 qqid3 a1 a2 a3 b1 b2 b3 c1 c2 c3
DP005205 DP005206 DP005207 0.49 0.934 0.888 -2 -1.793 -0.073 0.019 0.095 0.024

In the third data set, I retrieved the one record and tried to put the data in four arrays as qid, a, b, and c and output the result to log to check if the data were correctly retrieved. Following is the related piece of code
if _N_ = 1 then do;
set itemarr;
retain qqid1-qqid%left(&itemno.) a1-a%left(&itemno.) b1-b%left(&itemno.) c1-c%left(&itemno.);
array qqid (*) qqid1-qqid%left(&itemno.);
array a (*) a1-a%left(&itemno.);
array b (*) b1-b%left(&itemno.);
array c (*) c1-c%left(&itemno.);
do i = 1 to &itemno.;
if qqid(i) ne '' then put qqid(i) a(i) b(i) c(i);
end;
end;

The macro variable &itemno.=3 here. But the log shows the retrieved result with two incorrect b values -2 and -0 as
qid a b c
DP005205 0.49 -2 0.019
DP005206 0.934 -2 0.095
DP005207 0.888 -0 0.024

It seems the problem is associated with rounding. But why only these two values cannot be retrieved correctly?

Thanks
Ming
Super Contributor
Super Contributor
Posts: 3,174

Re: SAS array

I executed your code as documented, and I do not get the problem - the b1-b3 variables are accurate.

You would benefit from adding some PUTLOG _ALL_; commands in your code to monitor each data step pass.

Scott Barry
SBBWorks, Inc.
New Contributor
Posts: 2

Re: SAS array

I restarted my SAS and still got the same problem. Did you use SAS version 9? I got the problem solved by adding in the following code before the set statement. But I still don't know why.

informat b 6.3;
format b 6.3;

Thanks!!
Ming
Super Contributor
Super Contributor
Posts: 3,174

Re: SAS array

I don't see how - SAS-standard formats truncate normally. SAS 9.1.3 SP4 system - both Windows and IBM z/OS (mainframe) flavors. You must have some other code influencing the outcome of your un-transposed output which is not revealed in what you posted, other than the final variable values.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 3 replies
  • 127 views
  • 0 likes
  • 2 in conversation