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

Dear all,

I have the following dataset

IDREGIONNUMTYPE
NYus;ne1015; 10x16
BOus;ne1015; 10x17
IDnonus1018

I would like to add another column "REGION_NUMTYPE" which has all the combinations of region and num type per row separated by the ";"

IDREGIONNUMTYPEREGION_NUMTYPE
NYus;ne1015; 10x16us1015; us10x16;ne1015;ne10x16
BOus;ne1015; 10x17us1015; us10x17;ne1015;ne10x17
IDnonus1018nonus1018

Is there a simple way to do this ? Many Thanks for your help

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

You can also trying using Hash to be more dynamic.

data have;

input ID :$      REGION :$20.      NUMTYPE :$&20.;

cards4;;;;

NY    us;ne 1015; 10x16

BO    us;ne 1015; 10x17

ID    nonus 1018

;;;;

data want;

  set have;

  length region_numtype $ 100;

    array re(10) /*arbituary dimension*/ $10 _temporary_;

      array num(10) $10 _temporary_;

do i=1 by 1 while (not missing (scan(region,i,';')));

     re(i)=scan(region,i,';');

         do j=1 by 1 while (not missing (scan(numtype,j,';')));

num(j)=scan(numtype,j,';');

             region_numtype=catx(';',region_numtype,cats(re(i),num(j)));

            end;

  end;

  drop i j;

  run;


Haikuo

View solution in original post

2 REPLIES 2
Haikuo
Onyx | Level 15

You can also trying using Hash to be more dynamic.

data have;

input ID :$      REGION :$20.      NUMTYPE :$&20.;

cards4;;;;

NY    us;ne 1015; 10x16

BO    us;ne 1015; 10x17

ID    nonus 1018

;;;;

data want;

  set have;

  length region_numtype $ 100;

    array re(10) /*arbituary dimension*/ $10 _temporary_;

      array num(10) $10 _temporary_;

do i=1 by 1 while (not missing (scan(region,i,';')));

     re(i)=scan(region,i,';');

         do j=1 by 1 while (not missing (scan(numtype,j,';')));

num(j)=scan(numtype,j,';');

             region_numtype=catx(';',region_numtype,cats(re(i),num(j)));

            end;

  end;

  drop i j;

  run;


Haikuo

hdg
Obsidian | Level 7 hdg
Obsidian | Level 7

Thanks a lot Haikuo. super efficient really cut down my processing time.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1238 views
  • 0 likes
  • 2 in conversation