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
I don't see any first/last in the code?
Transpose tutorial
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/
Transpose via array tutorial:
https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/
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 ...
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"""
;;;;
I don't see any first/last in the code?
Transpose tutorial
https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/
Transpose via array tutorial:
https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.