BookmarkSubscribeRSS Feed
Ovaty
Fluorite | Level 6

Hi guys, good Morning !

 

I need to do a transpose table only by some variables.

I've try and has no success.

 

Base table

MaterialYYMMODIDORD_1ORD_2...ORD_23
11041120180853342510BA00020902AC15870200  
11041120180853342510BA00020906AC15870600  
11041120180853342510BA00020915AC15894100  
11041120190153975720BA00023631AC16139200  
11041120190153975720BA00023638AC16139900  
11041120190153975720BA00023679AC16193100  
11041120190153975720BA00023682AC16193400  

 

Want table

MaterialYYMMODIDORD
11041120180853342510AC15870200
11041120180853342510AC15870600
11041120180853342510AC15894100
11041120180853342510BA00020902
11041120180853342510BA00020906
11041120180853342510BA00020915
11041120190153975720AC16139200
11041120190153975720AC16139900
11041120190153975720AC16193100
11041120190153975720AC16193400
11041120190153975720BA00023631
11041120190153975720BA00023638
11041120190153975720BA00023679
11041120190153975720BA00023682

 

Thanks a lot!

Gustavo

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

So you want to keep data only for ORD10 and ORD20, correct?

Ovaty
Fluorite | Level 6

Hi Kurt, thanks for your fast response, but I've no success yet!

 

Look the result:

 

MaterialYYMMODIDordCOL2COL3COL4
11041120180853342510BA00020902BA00020906BA00020915 
11041120180853342510AC15870200AC15870600AC15894100 
11041120190153975720BA00023631BA00023638BA00023679BA00023682
11041120190153975720AC16139200AC16139900AC16193100AC16193400
Kurt_Bremser
Super User

Big hint: supplying example data in usable form (see the following code) is EXTREMELY helpful, as it gives us something to test against.

Without data in readily usable form (data step with datalines), you'll get untested "shots from the hip" that might work as expected.

data have;
input Material $ YYMM :$6. OD :$6. ID :2. ORD_1 :$10. ORD_2 :$10.;
datalines;
110411 201808 533425 10 BA00020902 AC15870200
110411 201808 533425 10 BA00020906 AC15870600
110411 201808 533425 10 BA00020915 AC15894100
110411 201901 539757 20 BA00023631 AC16139200
110411 201901 539757 20 BA00023638 AC16139900
110411 201901 539757 20 BA00023679 AC16193100
110411 201901 539757 20 BA00023682 AC16193400
;

data int1;
set have;
index = _N_;
run;

proc transpose
  data=int1
  out=want (drop=index _name_ rename=(col1=ord))
;
by index Material YYMM OD ID;
var ord_1 ord_2;
run;

proc sort data=want;
by Material YYMM OD ID ord;
run;

proc print data=want noobs;
run;

Result:

Material     YYMM       OD      ID       ord

 110411     201808    533425    10    AC15870200
 110411     201808    533425    10    AC15870600
 110411     201808    533425    10    AC15894100
 110411     201808    533425    10    BA00020902
 110411     201808    533425    10    BA00020906
 110411     201808    533425    10    BA00020915
 110411     201901    539757    20    AC16139200
 110411     201901    539757    20    AC16139900
 110411     201901    539757    20    AC16193100
 110411     201901    539757    20    AC16193400
 110411     201901    539757    20    BA00023631
 110411     201901    539757    20    BA00023638
 110411     201901    539757    20    BA00023679
 110411     201901    539757    20    BA00023682

matches your initial requirement.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 866 views
  • 0 likes
  • 3 in conversation