Create many observations from one record

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Create many observations from one record

Hello,

How can I achieve the following?

One record with many different fields.

DATA ACT.TMP;                   );

   INFILE INDB MISSOVER;

   INPUT         

        @0100 ACCT13                     7.  /*ACCOUNT NUMBER     */

        @0238 TOTEX12        PD008.3  /*ACT-AR-EXPSR-120-AM       */

        @0246 TOTEX15        PD008.3  /*ACT-AR-EXPSR-150-AM       */

        @0415 ANNVDT         PD004.   /*ACT-ANNIV-DT              */

         ;

I want to write this out like the following and assign a new variable to each different value:

ACCT13        New Var 

1234567       Z0033              345.00                               This record for TOTEX12

1234567       Z0005              622.00                               This record for TOTEX15

1234567       Z0010              2013200                            This record for ANNIVDT

8765432       Z0033              150.00                               This record for TOTEX12

8765432       Z0005                80.00                               This record for TOTEX15

8765432       Z0010              2013188                            This record for ANNIVDT

......etc....

Any suggestions on how to accomplish this??


Accepted Solutions
Solution
‎07-25-2013 07:34 PM
Super Contributor
Posts: 307

Re: Create many observations from one record

Try something like this. Note that I am assuming that all the input variables in ACT.TMP are numeric.

data accounts (keep=account newvar vardesc varvalue);

   set act.tmp ;

   rename acct13 = account;

   array tmp{3} totex12 totex15 annivdt ;

   do j = 1 to 3 ;

     if tmp{j} ne . then do;

    varvalue = tmp{j};

    if j = 1 then do ;

     vardesc = 'TOTEX12';

  newvar = 'Z0033';

    end;

    else if j = 2 then do ;

     vardesc = 'TOTEX15';

  newvar = 'Z0005';

    end;

    else if j = 3 then do ;

     vardesc = 'ANNIVDT';

  newvar = 'Z0010';

    end;

     output;

     end;

   end;

run;

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Create many observations from one record

The way you show your results doesn't quite match the discription of "a new variable to each different value". The appearance suggests one variable whose value changes between Z0033, Z0005 and Z0010. Do want to create a new dataset or actually write to output or an ODS destination?

Occasional Contributor
Posts: 5

Re: Create many observations from one record

I want to create a new dataset.  I want to define a new Zcode based on each variable.  Ex. All TOTEX12 will have a Zcode of Z0033 - All TOTEX15 will have a Zcode of Z0005, etc...
Maybe my terminology is not quite correct.

Solution
‎07-25-2013 07:34 PM
Super Contributor
Posts: 307

Re: Create many observations from one record

Try something like this. Note that I am assuming that all the input variables in ACT.TMP are numeric.

data accounts (keep=account newvar vardesc varvalue);

   set act.tmp ;

   rename acct13 = account;

   array tmp{3} totex12 totex15 annivdt ;

   do j = 1 to 3 ;

     if tmp{j} ne . then do;

    varvalue = tmp{j};

    if j = 1 then do ;

     vardesc = 'TOTEX12';

  newvar = 'Z0033';

    end;

    else if j = 2 then do ;

     vardesc = 'TOTEX15';

  newvar = 'Z0005';

    end;

    else if j = 3 then do ;

     vardesc = 'ANNIVDT';

  newvar = 'Z0010';

    end;

     output;

     end;

   end;

run;

Occasional Contributor
Posts: 5

Re: Create many observations from one record

Fugue,

Thank you very much for your response.  It works just fine.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 206 views
  • 0 likes
  • 3 in conversation