Dear all,
I have been breaking my head over the below logic. Kindly help:
Have data set:
ID | Status | Code | System | Name | Value | Rule_Label |
123XXX | Active | BDD | EXX | City | C07 | City: Numeric,City: Special Characters |
123XXX | Active | CDD | ABB | City | C07 | City: Numeric,City: Special Characters |
123XXX | Active | ADD | CAA | City | - | City: Special Characters |
123XXX | Active | ADD | CAA | City | Occupation: Blank | |
456XXX | Inactive | ADD | CAA | State | State: Blank | |
456XXX | Inactive | ADD | CAA | Code | 111 | mismatch |
456XXX | Active | CDD | CAA | Code | \M | blank |
456XXX | Active | CDD | CAA | City | c13 | City: Numeric,City: Special Characters |
789XXX | Inactive | CDD | ABB | Code | N41 | City: Numeric,City: Special Characters |
910XXX | Active | MMM | ABB | City | 8 | City: Numeric,City: Special Characters |
910XXX | Active | MMM | EXX | City | - | City: Special Characters |
910XXX | Active | MMM | EXX | State | State: Blank |
Need data set (attached
please let me know the logic
Please don't post data in Excel format files. Many firewalls prevent the downloading of such files, and sensible people don't open Office files from the web, anyway, because of security reasons.
Use the {i} subwindow to post fixed-font text.
At least use the same method you used for the "have" data.
Hi Kurt,
Thank you for the advise. Noted and Thank you!
Have data :
ID | Status | Code | System | Name | Value | Rule_Label |
123XXX | Active | BDD | EXX | City | C07 | City: Numeric,City: Special Characters |
123XXX | Active | CDD | ABB | City | C07 | City: Numeric,City: Special Characters |
123XXX | Active | ADD | CAA | City | - | City: Special Characters |
123XXX | Active | ADD | CAA | City | Occupation: Blank | |
456XXX | Inactive | ADD | CAA | State | State: Blank | |
456XXX | Inactive | ADD | CAA | Code | 111 | mismatch |
456XXX | Active | CDD | CAA | Code | \M | blank |
456XXX | Active | CDD | CAA | City | c13 | City: Numeric,City: Special Characters |
789XXX | Inactive | CDD | ABB | Code | N41 | City: Numeric,City: Special Characters |
910XXX | Active | MMM | ABB | City | 8 | City: Numeric,City: Special Characters |
Needed data set:
ID | Status | Code | EXX | ABB | CAA | EXX | ABB | CAA | EXX | CAA | ABB | ||||||||
Code | Rule Label | Code | Rule Label | Code | Rule Label | City | Rule Label | City | Rule Label | City | Rule Label | State | Rule Label | State | Rule Label | State | |||
123XXX | |||||||||||||||||||
456XXX | |||||||||||||||||||
456XXX | |||||||||||||||||||
456XXX | |||||||||||||||||||
456XXX | |||||||||||||||||||
789XXX | |||||||||||||||||||
910XXX | |||||||||||||||||||
910XXX |
Please help..
Seems to me that proc transpose will not be able to handle this, so you will have to do it in a data step.
Some questions:
Do you know beforehand how many distinct values for "system" and "name" are present, or will that change over time?
And why is there only one line for 123XXX, but four lines for 456XXX?
What happens with the original column "value"?
Which original value for "code" should be preserved in the case of 123XXX?
I still don't completely understand your requirements, but my basic approach would be:
- sort dataset byID
- In a data step:
- use by ID;
- define the new variables (LENGTH, FORMAT) and RETAIN them
- with if first.ID, set the variables to missing values
- then, set variables for each record, as per requirements
- with if last.id then output; write one record per ID
If the content of the selection variables is not pre-determined, you will have to wrap everything into a macro that first determines all possible values, saves them into lists, and then create the code dynamically from those lists.
But first I'd construct the data step with given values to make sure the code works as desired.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.