SAS Stack up question

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

SAS Stack up question

I'm trying to do something like this below...

please let me know how to do using sas

Input dataset                   Desired output

VAR1 VAR2                   VAR1

------   --------                   --------------

DB2   BASE1                  DB2

DB2   BASE2                  BASE1

SQL   BASE3                  BASE2

SQL   BASE7                  SQL

ORC  TOSS6                   BASE3

ORC   ROSS7                  BASE7

                                       ORC

                                       TOSS6

                                        TOSS7


Accepted Solutions
Solution
‎08-26-2011 01:47 PM
Frequent Contributor
Posts: 104

SAS Stack up question

The desired output is a report or a dataset?

If it's a report then there are amny ways to do it, e.g., proc print.

If it's a dataset, then I don't understand why it is a good idea since the ability to distinguish between the two columns is lost.

But technically this would do it:

proc sort data=in;

   by var1 var2;

run;

data out;

   set in;

   by var1;

  if first.var1 then do;

     var=var1;

    output;

   end;

   var=var2;

   output;

   keep var;

run;

View solution in original post


All Replies
Contributor
Posts: 72

SAS Stack up question

How about something like this:

data out_ds;
   set in_ds;
   if var1 ~= '' then output;
   if var2 ~= '' then
      do;
         var1 = var2;
         output;
      end;
run;


proc sort data=out_ds nodupkey;
   by var1;
run;

Contributor
Posts: 22

SAS Stack up question

Robin, Thanks. The result is little bit different from what I expected. But your response is very helpful. It gave me an idea how to go thru it.

Solution
‎08-26-2011 01:47 PM
Frequent Contributor
Posts: 104

SAS Stack up question

The desired output is a report or a dataset?

If it's a report then there are amny ways to do it, e.g., proc print.

If it's a dataset, then I don't understand why it is a good idea since the ability to distinguish between the two columns is lost.

But technically this would do it:

proc sort data=in;

   by var1 var2;

run;

data out;

   set in;

   by var1;

  if first.var1 then do;

     var=var1;

    output;

   end;

   var=var2;

   output;

   keep var;

run;

Contributor
Posts: 22

SAS Stack up question

Thanks Dling for your response. It worked out.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 241 views
  • 3 likes
  • 3 in conversation