Search code examples
sas

How can I create multiple observations from a single observation (two variables) in SAS


I would like your help with creating multiple observations from one observation.
How can i get this done?

My data set looks like this.

Name | Date       | X_Number | Y_Number |
-----|------------|----------|----------|
John | 01-01-2024 | 646463   |          |
Jane | 14-12-2023 | 456537   | 6384563  |
Jim  | 03-05-2022 | 463940   |          |

Desired output

Name | Date       | Number  |
-----|------------|---------|
John | 01-01-2024 | 646463  |
Jane | 14-12-2023 | 456537  | 
Jane | 14-12-2023 | 6384563 |
Jim  | 03-05-2022 | 463940  |

Any help much appriciated.


Solution

  • Try this

    data have;
    input Name $ Date :ddmmyy10. X_Number Y_Number;
    infile datalines missover;
    format Date ddmmyy10.;
    datalines;                     
    John 01-01-2024 646463          
    Jane 14-12-2023 456537 6384563  
    Jim  03-05-2022 463940          
    ;
    
    data want;
       set have;
       array n X_Number Y_Number;
       do over n;
          if n ne . then do;
             number = n; output;
          end;
       end;
       keep name date number;
    run;