I have problem transposing to long to wide
Here is what i have:
| COL1 | Plan | target_code | Name | Question_ID | Parent Question | Child Question |
| Chicago | Plan A | 1234 | p1 | Q001 | address | city |
| IL | Plan A | 1234 | p1 | Q002 | address | state |
| Red | Plan A | 1234 | p1 | Q003 | Program | Color |
| 2009 | Plan A | 1234 | p1 | Q004 | Program | Start Year |
| New York | Plan A | 1221 | p2 | Q001 | address | city |
| NY | Plan A | 1221 | p2 | Q002 | address | state |
| Blue | Plan A | 1221 | p2 | Q003 | Program | Color |
| 2009 | Plan A | 1221 | p2 | Q004 | Program | Start Year |
Here is what i want:
| address | address | Program | Program | |||
| city | state | Color | Start Year | |||
| Plan | target_code | Name | Q001 | Q002 | Q003 | Q004 |
| Plan A | 1234 | p1 | Chicago | IL | Red | 2009 |
| Plan A | 1221 | p2 | New York | NY | Blue | 2009 |
I have this code here, but the output is not what i want. It is combining Question_ID, 'Parent Question'n, and 'Child Question'n all into one column.
proc transpose data=prg_final2 out= final_report (drop=_NAME_);
by Plan target_code Name;
id Question_ID 'Parent Question'n 'Child Question'n;
var COL1;
run;
just edit id statement:
proc transpose data=prg_final2 out= final_report (drop=_NAME_) ;
by Plan target_code Name;
id Question_ID;
var COL1;
run;
and then:
data final_report2;
set final_report;
label Q001 ='address city' Q002='address state' .... etc;
run;
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.