I need some advice I need to transpose 2 variables from a long dataset to a wide dataset In the long dataset dad19sas.diagnosis the by variable dad_transaction_id repeats or there are
duplicates for every different value of the var variables Can i transpose both variables for a dad_transaction_id in a single proc transpose step
or do i do it in multiple steps. If in multiple steps then do I use the merge to combine in a single dataset I then wa
/**Do I transpose in 2 seperate steps or a sinle step**/
proc transpose data = dad19sas.diagnosis out = diagcode
prefix = DIAG_CODE_ ;
var diag_icd10_code ;
by dad_transaction_id;
run;
proc transpose data = dad19sas.diagnosis out = diagtype
prefix = DIAG_type_code ;
var diag_type_code ;
by dad_transaction_id;
run;
/**Merge datasets by dad_transaction_id?**/
data diagcode;set diagcode; drop _NAME_ _LABEL_;run;
data diagcode;
set diagcode;
array diag{*} DIAG_CODE_: ;
array diag_type{*} DIAG_TYPE_CODE_:
do i = 1 to dim(diag);
if diag{i} in: ('Z37') then DIAG_HD = 1;
end;
do i = 1 to dim(diag_type);
if diag_type{i} in: ('M' or '3') then DIAG_HD_type = 1;
end;
/** Keep records with selected diagnosis above and where the type is M or 3 in any of the array elements*/
*if DIAG_HD = 1 ;
run;
nt to use the array statement on the transposed dataset to keep records
where diag_type_code =M or 3 and Please advise how I can perform the above
Can you please post some sample data?
@tarheel13 wrote:
Can you please post some sample data?
Showing both starting data and desired result for the starting data.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.
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!
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.