DATA Step, Macro, Functions and more

transposing

Reply
Contributor
Posts: 35

transposing

Hello 

 

I have below dataset 

 

data new;

input room $ equpi $10.;

datalines;

A printer

A fax

A monitor

B fax

B monitor

C LCD

D montior

;

run;

 

Below is the output I want 

 

 
PROC Star
Posts: 551

Re: transposing

Can you post the picture of your desired output in a different format? For some reason it is not showing.

Contributor
Posts: 35

Re: transposing

Room

printer

Fax

Monitor

LCD

A

TRUE

TRUE

TRUE

FALSE

B

FALSE

TRUE

TRUE

FALSE

C

FALSE

FALSE

FALSE

TRUE

D

FALSE

FALSE

TRUE

FALSE

 

 

Is it showing now ?

Super User
Posts: 6,936

Re: transposing

data new;
input room $ equpi $10.;
datalines;
A printer
A fax
A monitor
B fax
B monitor
C LCD
D monitor
;
run;

proc transpose data=new out=want (drop=_name_);
by room;
id equpi;
var equpi;
run;

data want;
set want;
array chars {*} _character_;
do i = 2 to dim(chars);
  if missing(chars{i})
  then chars{i} = 'FALSE';
  else chars{i} = 'TRUE';
end;
drop i;
run;
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Respected Advisor
Posts: 3,777

Re: transposing

[ Edited ]
data new;
input room $ equpi :$10.;
datalines;
A printer
A fax
A monitor
B fax
B monitor
C LCD
D monitor
;
run;
proc summary data=new nway completetypes;
   class room;
   class equpi / order=data;
   output out=full(drop=_type_);
   run;
proc transpose data=full out=wide(drop=_name_);
   by room;
   var _freq_;
   id equpi;
   run;
proc print;
   run;

Capture.PNG 

Contributor
Posts: 35

Re: transposing

I have attached the output in Xls Sheet that i have attached 

Valued Guide
Posts: 505

Re: transposing

I assume you want numeric 0/1(bolean logicals) displayed
as numeric(bolean logicals) FALSE/TRUE  and
not the character strings FALSE/TRUE.

Somewhere buried in excel is an option to display 0/1 as logical True/False.

data have;
input room $ equpi :$10.;
datalines;
A printer
A fax
A monitor
B fax
B monitor
C LCD
D monitor
;
run;

libname xel "d:/xls/truefalse.xlsx";
Ods Exclude All;
Ods Output Observed=xel.want(Rename=Label=Gov);
Proc Corresp Data=have Observed dim=1;
   Table room, equpi;
Run;
Ods Select All;
libname xel clear;

SOAPBOX ON
Once upon a time  tools/options/formula evaluation?, provided a TRUE/FALSE(logical)  format.
Excel like SAS does not honor legacy fnctionality, a command line would force SAS
to honor legacy scripting at least.
Bur a command line is only for programmers?
SOAPBOX OFF

proc print data=want;run;


 Obs    GOV    LCD    FAX    MONITOR    PRINTER    SUM

  1     A       0      1        1          1        3
  2     B       0      1        1          0        2
  3     C       1      0        0          0        1
  4     D       0      0        1          0        1
  5     Sum     1      2        3          1        7

You can use a formula in excel to get TRUE/FALSE text

=IF(RC[1]=1,"TRUE",IF(RC1=0,"FALSE","NULL"))

Ask a Question
Discussion stats
  • 6 replies
  • 193 views
  • 3 likes
  • 5 in conversation