Solved

# storing unque values from 15 columns and "x" rows   in SAS

Posted on 2014-03-25
324 Views
Experts,

I have pieces of this puzzle, but now to put it together.

I have a record that has error codes in colums ERR01 - ERR15  respectively,  Each member can have multiple records and the codes can be repeated.

I have the number of records per member in the first column  called "n".  Does anyone know how in SAS I can loop through the table ERR01 - ERR15 and the respective rows and keep only distinct error codes and omitting blanks.
0
Question by:morinia
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 14

Expert Comment

ID: 39954907
Could provide examples to help better visualize what you have and trying to achieve?
0

LVL 11

Accepted Solution

theartfuldazzler earned 500 total points
ID: 39955240
Hi

if I understand you correctly, you want something like this?

``````DATA Test;
INFORMAT n 3. Cust_no 5. ERR01 ERR02 ERR03 ERR04 ERR05 ERR06 \$4.;
INFILE CARDS DLM= '|' DSD TRUNCOVER;
INPUT n Cust_no ERR01  ERR02   ERR03   ERR04   ERR05   ERR06  ;
CARDS;
2|1234|E1|E2||E3||E1
2|1234|E3|||||
1|1235|E1|E2
3|1236|E1|E2|E3|E4|E5|
3|1236|E1|E2|E3|E4|E5|
3|1236|E6|E2|E7|E4|E5|
;RUN;

PROC SORT DATA=Test;
BY Cust_no;
RUN;

DATA Test2;
SET Test;
ARRAY ErrorArr ERR01 - ERR06;
Do i = 1 to 6;
Error = ErrorArr[i];
IF Error ~= " " then OUTPUT;
END;
DROP i ERR01 - Err06;
RUN;

PROC SORT DATA=test2 NODUPKEY;
BY Cust_no Error;
RUN;

DATA Test2;
set test2;
BY Cust_no;
RETAIN i;
IF First.Cust_no then i = 0;
i = i + 1;
ColName = 'ERR'||PUT(i,z2.);
DROP i;
RUN;

PROC TRANSPOSE DATA=Test2 OUT=Test_Final;
BY Cust_no;
ID ColName;
VAR Error;
RUN;
``````
0

Author Closing Comment

ID: 39955969
Worked like a charm.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying our service is a grudge match between customer benefits and customer pain. In one corner, rolling out fixes (yay!) and delivering new features (double yay!). In the other corner, training on new features (boo – sounds like work), and chan…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
###### Suggested Courses
Course of the Month2 days, 18 hours left to enroll