Solved

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

Posted on 2014-03-25
3
313 Views
Last Modified: 2016-02-10
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
Comment
Question by:morinia
3 Comments
 
LVL 14

Expert Comment

by:Aloysius Low
ID: 39954907
Could provide examples to help better visualize what you have and trying to achieve?
0
 
LVL 11

Accepted Solution

by:
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;

Open in new window

0
 

Author Closing Comment

by:morinia
ID: 39955969
Worked like a charm.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A Short Story about the Best File Recovery Software – Acronis True Image 2017
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now