BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kjd2121
Calcite | Level 5

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??

1 ACCEPTED SOLUTION

Accepted Solutions
Fugue
Quartz | Level 8

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

4 REPLIES 4
ballardw
Super User

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?

kjd2121
Calcite | Level 5

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.

Fugue
Quartz | Level 8

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;

kjd2121
Calcite | Level 5

Fugue,

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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