BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aj34321
Quartz | Level 8

Hey Guys,

 

Need help on this output, Can some help with the code for getting the output mentioned in attached excel.

Excel file has one tabsheet named "Input Dataset"

Output is what i want.

 

Thanks, Anil

1 ACCEPTED SOLUTION
4 REPLIES 4
Reeza
Super User

PROC TRANSPOSE should work, if its not working please post your code and sample data as a data step.

 

Instructions on providing data is here:

How to create a data step version of your data AKA... - SAS Support ...

 

 

aj34321
Quartz | Level 8

Hi Reeza, 

 

I was trying by first.var and last.var but not in a good shape at all.

Here's the sample dataset. 

 

data input;
infile datalines dsd truncover;
input rule_set_nm:$54. rule_seq_no:BEST2. expression_type:$9. expression_order:BEST1. conditional_nm:$6. lhs_term:$26. expression:$158.;
datalines4;
PORT_1,1,CONDITION,1,if,ORIGIN,
PORT_1,1,CONDITION,2,if,CURRENT,"IN (""G10"", ""G9"", ""H2"", ""H3"", ""H4"", ""H5"", ""H6"", ""H7"", ""H8"", ""I"", ""I1"")"
PORT_1,1,ACTION,1,if,STAGE,"""Stage3"""
PORT_1,2,CONDITION,1,elseif,ORIGIN,"IN(""A99"", ""A98"", ""A95"")"
PORT_1,2,CONDITION,2,elseif,CURRENT,"IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"")"
PORT_1,2,ACTION,1,elseif,STAGE,"""Stage1"""
PORT_1,3,CONDITION,1,elseif,ORIGIN,"IN(""A92"", ""A90"", ""G10"", ""G11"", ""G9"", ""H8"", ""H7"", ""H6"", ""H5"", ""H4"", ""H3"", ""H2"", ""I1"", ""I"")"
PORT_1,3,CONDITION,2,elseif,CURRENT,"IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"")"
PORT_1,3,ACTION,1,elseif,STAGE,"""Stage1"""
PORT_1,4,CONDITION,1,elseif,ORIGIN,"IN(""B87"", ""B82"", ""B78"", ""B77"")"
PORT_1,4,CONDITION,2,elseif,CURRENT,"IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"")"
PORT_1,4,ACTION,1,elseif,STAGE,"""Stage1"""
PORT_1,5,CONDITION,1,elseif,ORIGIN,"IN(""C72"", ""C67"")"
PORT_1,5,CONDITION,2,elseif,CURRENT,"IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"", ""D52"")"
PORT_1,5,ACTION,1,elseif,STAGE,"""Stage1"""
PORT_1,6,CONDITION,1,elseif,ORIGIN,"IN(""C62"")"
PORT_1,6,CONDITION,2,elseif,CURRENT,"IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"", ""D52"", ""D49"")"
PORT_1,6,ACTION,1,elseif,STAGE,"""Stage1"""
PORT_1,7,CONDITION,1,elseif,ORIGIN,"IN(""C60"", ""D57"")"
PORT_1,7,CONDITION,2,elseif,CURRENT,"IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"", ""D52"", ""D49"", ""D47"", ""D46"")"
PORT_1,7,ACTION,1,elseif,STAGE,"""Stage1"""
PORT_1,8,CONDITION,1,elseif,ORIGIN,"IN(""D52"", ""D49"", ""D47"")"
PORT_1,8,CONDITION,2,elseif,CURRENT,"IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"", ""D52"", ""D49"", ""D47"", ""D46"", ""D45"", ""D44"", ""D43"")"
PORT_1,8,ACTION,1,elseif,STAGE,"""Stage1"""
PORT_1,9,CONDITION,1,elseif,ORIGIN,"IN (""D46"", ""D45"", ""D44"", ""D43"", ""D42"", ""E35"", ""F21"", """", ""N/A"")"
PORT_1,9,CONDITION,2,elseif,CURRENT,"IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"", ""D52"", ""D49"", ""D47"", ""D46"", ""D45"", ""D44"", ""D43"", ""D42"")"
PORT_1,9,ACTION,1,elseif,STAGE,"""Stage1"""
PORT_1,10,ACTION,1,elseif,STAGE,"""Stage2"""
;;;;

data output;
length
conditional_nm $ 6
origin $ 89
current $ 153
stage $ 8 ;
format
conditional_nm $char6.
origin $char89.
current $char153.
stage $char8. ;
informat
conditional_nm $char6.
origin $char89.
current $char153.
stage $char8. ;
infile datalines4
dlm='7f'x
missover
dsd ;
input
conditional_nm : $char6.
origin : $char89.
current : $char153.
stage : $char8. ;
datalines4;
if"IN (""G10"", ""G9"", ""H2"", ""H3"", ""H4"", ""H5"", ""H6"", ""H7"", ""H8"", ""I"", ""I1"")""""Stage3"""
elseif"IN(""A99"", ""A98"", ""A95"")""IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"")""""Stage1"""
elseif"IN(""A92"", ""A90"", ""G10"", ""G11"", ""G9"", ""H8"", ""H7"", ""H6"", ""H5"", ""H4"", ""H3"", ""H2"", ""I1"", ""I"")""IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"")""""Stage1"""
elseif"IN(""B87"", ""B82"", ""B78"", ""B77"")""IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"")""""Stage1"""
elseif"IN(""C72"", ""C67"")""IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"", ""D52"")""""Stage1"""
elseif"IN(""C62"")""IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"", ""D52"", ""D49"")""""Stage1"""
elseif"IN(""C60"", ""D57"")""IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"", ""D52"", ""D49"", ""D47"", ""D46"")""""Stage1"""
elseif"IN(""D52"", ""D49"", ""D47"")""IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"", ""D52"", ""D49"", ""D47"", ""D46"", ""D45"", ""D44"", ""D43"")""""Stage1"""
elseif"IN (""D46"", ""D45"", ""D44"", ""D43"", ""D42"", ""E35"", ""F21"", """", ""N/A"")""IN(""A99"", ""A98"", ""A95"", ""A92"", ""A90"",""B87"", ""B82"", ""B78"", ""B77"",""C72"", ""C67"",""C62"", ""C60"", ""D57"", ""D52"", ""D49"", ""D47"", ""D46"", ""D45"", ""D44"", ""D43"", ""D42"")""""Stage1"""
elseif  """Stage2"""
;;;;

 

aj34321
Quartz | Level 8

I did it using proc transpose as you suggested before and it worked for my requirement.

 

proc transpose data=sample out=work.trnstransposed let name=source label=label;
by rule_seq_no;
id lhs_term;
var expression;
run;
quit;

 

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1343 views
  • 0 likes
  • 2 in conversation