Search code examples
sas

SAS combine two columns in a dataset


I got a dataset looks like this:

Category Sub-Category value
A 1 xx
A 2 xx
A 3 xx
A 4 xx
B 1 xx
B 2 xx
B 3 xx
B 4 xx

I want to combine the first two columns and create a new dataset with the new category(rows) and it should looks like this:

Category Value
A
1 xx
2 xx
3 xx
4 xx
B
1 xx
2 xx
3 xx
4 xx
...

Can anyone help me with that using SAS?

Thanks in advance!


Solution

  • That seems pretty useless as a DATASET.

    Why not just print the original dataset.

    proc print data=have;
      by category;
    run;
    

    Result:

    enter image description here

    If you did want to generate that goofy dataset you could try interleaving two copies of the original data.

    data want;
      set have(in=in1) have(in=in2);
      by category;
      if in1 then do;
        if first.category then call missing(value);
        else delete;
      end;
      if in2 then category=cats(subcategory);
      drop subcategory ;
    run;
    

    Result:

    enter image description here