BookmarkSubscribeRSS Feed
morten1
Calcite | Level 5

Hi, 

 

I have got a dataset with information in the following format: 

 LocationMethodVar 1Var 2
Person 1x113
Person 1y157
Person 1x224
Person 1y268
Person 2x1911
Person 2y11315
Person 2z11719
Person 2x21012
Person 2y21416
Person 2z21820

 

 

 

 

Is it possible to move some of the rows, so that I can compare the two methods in two adjacent columns, like this?

 

  Var 1Var 2
 LocationMethod 1Method 2Method 1Method 2
Person 1x1234
Person 1y5678
Person 2x9101112
Person 2y13141516
Person 2z17181920

 

I don't think this is possible in excel, and I am new to SAS. Any suggestions? Or do I have to plot it manully?

 

Thank you,

Morten

 

4 REPLIES 4
Astounding
PROC Star

This is untested, but it should give you a quick-and-dirty version of what you asked for.

 

proc tabulate data=have;

   class person location method;

   var var1 var2;

   tables person * location, (var1 var2) * sum * method;

run;

morten1
Calcite | Level 5

Thank you, this works great. 

 

I get the results only in results viewer, and would like to have it as a SAS data set and as a new excel file. I have tried the ods html output as .xls file, but this gives me an excel sheet whit dots (instead of commas) and excel then automatically makes the values to dates. 

 

Is there a solution for:

1. Make a SAS data set from results in Results Viewer 

2. Get an excel sheet with the correct formatting (with commas, not converted as dates)? 

 

 

 

dcruik
Lapis Lazuli | Level 10

Here's another way to do what you're looking for.  It's not dynamic, but you could probably develop some additional code to make it dynamic if needed (as far as additional variables and methods other than 2 each).  Hope this helps!

 

data have;
input Person$ Location$ Method$ Var1 Var2;
datalines;
Person1 X 1 1 3
Person1 Y 1 5 7
Person1 X 2 2 4
Person1 Y 2 6 8
Person2 X 1 9 11
Person2 Y 1 13 15
Person2 Z 1 17 19
Person2 X 2 10 12
Person2 Y 2 14 16
Person2 Z 2 18 20
;
run;

%macro transform(method,var);
data &var._&method (Rename=(&var=&var._Method&method) Keep=Person Location &var);
set have;
Where Method="&method";
run;
%mend;

%transform(1,Var1)
%transform(2,Var1)
%transform(1,Var2)
%transform(2,Var2);

data want;
merge Var1_1
      Var1_2
      Var2_1
      Var2_2;
by Person Location;
run;
MadhuKorni
Quartz | Level 8


proc report data =have
out = have1(drop = _break_ rename =(_c3_ = Method1Var1 _c5_ = Method2Var1 _c4_ = Method1Var2 _c6_ = Method2Var2));
columns Person Location Method,(Var1 Var2);
define Person/group ;
define Location /Group;
define Method/across;
run;

Data Want;
retain Person Location Method1Var1 Method2Var1 Method1Var2 Method2Var2;
set Have1;
run;

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!

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
  • 971 views
  • 2 likes
  • 4 in conversation