<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Transposing a long dataset to wide with multiple variable types in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987769#M380072</link>
    <description>&lt;P&gt;Since you are using this BY statement in your PROC TRANPOSE&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by SID FormDateTime FirstName MiddleName LastName DOB;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To get duplicate observations you would need to have changes in one of those variables.&amp;nbsp; Are you sure that FORMDATETIME is the same of all observations you want to combine? What about the other 5 varaibles?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or are you just talking about the fact that you generated TWO datasets, but did not include a step to combine them?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge wide_num wide_char;
  by SID FormDateTime FirstName MiddleName LastName DOB;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also you will need to apply the FORMAT to the variables AFTEr the PROC TRANSPOSE step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example both DATE and TIME variables are numeric, so I would assume you put them into the WIDE_NUM dataset.&amp;nbsp; But if you do not attach a FORMAT to the resulting variable(s) then the values will be hard for humans to interpret.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 May 2026 01:28:34 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2026-05-12T01:28:34Z</dc:date>
    <item>
      <title>Transposing a long dataset to wide with multiple variable types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987749#M380068</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with several variable types (char, num, date, time, checkboxes, string) and I am trying to convert it to a wide format with 1 row per ID. I have created RESP_C, RESP_N,&amp;nbsp;RESP_DATE and RESP_TIME variables to assign the correct the appropriate values to each of these columns.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data prepared;&lt;BR /&gt;set joined;length RESP_C $1000 RESP_N 8 RESP_DATE 12 RESP_TIME 8;&lt;/P&gt;&lt;P&gt;RESP_C = strip(Response);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;select (upcase(Target_Type));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when ('DATE') do;&lt;BR /&gt;RESP_DATE = input(strip(Response), anydtdte.);&lt;BR /&gt;format RESP_DATE date9.;&lt;BR /&gt;RESP_C = "";&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when ('TIME') do;&lt;BR /&gt;RESP_TIME = input(strip(Response), anydttme.); /* NA 4/29: timepart is for mixed reponse, so removed it (date + time) */&lt;BR /&gt;format RESP_TIME timeampm.;&lt;BR /&gt;RESP_C = "";&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when ('CHECK') do;&lt;BR /&gt;if strip(Response) in ('Y','YES','TRUE','1','CHECKED','Selected') then RESP_N = 1; /* NA 4/29: Added 'Selected' to the list as that is the response of the form */&lt;BR /&gt;else if missing(Response) then RESP_N = .;&lt;BR /&gt;else RESP_N = 0;&lt;BR /&gt;/*format RESP_N 1.; */&lt;BR /&gt;RESP_C = "";&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when ('NUM') do;&lt;BR /&gt;RESP_N = input(strip(Response), best32.);&lt;BR /&gt;RESP_C = "";&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;otherwise do; /* CHAR */&lt;BR /&gt;/* keep RESP_C */&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=prepared;&lt;BR /&gt;by SID FormDateTime FirstName MiddleName LastName DOB;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/***********************************************************************&lt;BR /&gt;* 7) Transpose into wide:&lt;BR /&gt;* - Character targets (CHAR) -&amp;gt; wide_char&lt;BR /&gt;* - Numeric targets (DATE, TIME, NUM, CHECK) -&amp;gt; wide_num&lt;BR /&gt;***********************************************************************/&lt;/P&gt;&lt;P&gt;proc transpose data=prepared(where=(Target_Type='CHAR'))&lt;BR /&gt;out=wide_char(drop=_name_);&lt;BR /&gt;by SID FormDateTime FirstName MiddleName LastName DOB;&lt;BR /&gt;id VarName_ID;&lt;BR /&gt;var RESP_C;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=prepared(where=(Target_Type in ('DATE','TIME','NUM','CHECK')))&lt;BR /&gt;out=wide_num(drop=_name_);&lt;BR /&gt;format RESP_DATE date9. RESP_TIME timeampm.;&lt;BR /&gt;by SID FormDateTime FirstName MiddleName LastName DOB;&lt;BR /&gt;id VarName_ID;&lt;BR /&gt;var RESP_N RESP_DATE RESP_TIME;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, this is only working on some date values in the dataset and not applying uniformly to all the values. Additionally, after transposing each variable type is a unique row and not one row per ID.&lt;/P&gt;&lt;P&gt;I would appreciate any help in fixing this code. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2026 19:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987749#M380068</guid>
      <dc:creator>NandiniA</dc:creator>
      <dc:date>2026-05-11T19:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing a long dataset to wide with multiple variable types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987768#M380071</link>
      <description>&lt;P&gt;It looks like you currently have the data stored in a single character variable named RESPONSE.&lt;/P&gt;
&lt;P&gt;You appear to also have a variableTARGET_TYPE that appears to indicates what TYPE of variable needs to be created to store this particular RESPONSE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What variable has the NAME that you want to use for the new variable?&lt;/P&gt;
&lt;P&gt;What are the variables that uniquely identify the set of observations you want to transpose into one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you need code that works for this particular dataset, with its specific set of variables?&lt;/P&gt;
&lt;P&gt;If so then just write some code that that reads in all of the observations for the output observation in one iteration of the data step.&lt;/P&gt;
&lt;P&gt;So something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until (last.id);
    set have;
    by id;
    if NAME='DATE' then date=input(left(response),anydtdte.);
    else if NAME='AGE' then age=input(left(response),32.);
    ...
  end;
  drop NAME TARGET_TYPE RESPONSE ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or do you want a program that could convert ANY dataset?&amp;nbsp; If so then select the unique combinations of NAME and TARGET_TYPE from the dataset and use that to generate a program like the one above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For a more detailed answer provide a small example input dataset (as a working DATA step).&amp;nbsp; Also provide a data step that creates the dataset you want to get from that example input.&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2026 00:45:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987768#M380071</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-05-12T00:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing a long dataset to wide with multiple variable types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987769#M380072</link>
      <description>&lt;P&gt;Since you are using this BY statement in your PROC TRANPOSE&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by SID FormDateTime FirstName MiddleName LastName DOB;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To get duplicate observations you would need to have changes in one of those variables.&amp;nbsp; Are you sure that FORMDATETIME is the same of all observations you want to combine? What about the other 5 varaibles?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or are you just talking about the fact that you generated TWO datasets, but did not include a step to combine them?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  merge wide_num wide_char;
  by SID FormDateTime FirstName MiddleName LastName DOB;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also you will need to apply the FORMAT to the variables AFTEr the PROC TRANSPOSE step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example both DATE and TIME variables are numeric, so I would assume you put them into the WIDE_NUM dataset.&amp;nbsp; But if you do not attach a FORMAT to the resulting variable(s) then the values will be hard for humans to interpret.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2026 01:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987769#M380072</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-05-12T01:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing a long dataset to wide with multiple variable types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987774#M380073</link>
      <description>&lt;P&gt;Check the MERGE skill proposed by me,&amp;nbsp; Arthur.T and Matt :&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf" target="_blank" rel="noopener"&gt;http://support.sas.com/resources/papers/proceedings15/2785-2015.pdf&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;And could you post your sample data and the desired output to explain this question better?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id char $ num date :date9. time :time. ;
format date date9. time time.;
cards;
1 ss 23 1jan2010 09:20:21
1 ss 24 2jan2010 09:20:22
1 ss 25 3jan2010 09:20:23
2 ss 26 4jan2010 09:20:24
2 ss 27 5jan2010 09:20:25
;



data temp;
 set have;
 by id;
 if first.id then n=0;
 n+1;
run;
proc sql noprint;
select distinct(catt('temp(where=(n=',n,') rename=(
 char=char_',n,' num=num_',n,' date=date_',n,' time=time_',n,'))'))
 into :merge separated by ' '
   from temp;
quit;
data want;
merge &amp;amp;merge ;
by id;
drop n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And a more simple and convenient way is using proc summary+idgroup, but it has limit that each group have&amp;nbsp; 100 obs at most.&lt;/P&gt;
&lt;PRE&gt;data have;
input id char $ num date :date9. time :time. ;
format date date9. time time.;
cards;
1 ss 23 1jan2010 09:20:21
1 ss 24 2jan2010 09:20:22
1 ss 25 3jan2010 09:20:23
2 ss 26 4jan2010 09:20:24
2 ss 27 5jan2010 09:20:25
;
proc sql noprint;
select max(n) into :n from
(select count(*) as n  from have group by id);
quit;

proc summary data=have nway;
class id;
output out=want idgroup( out[&amp;amp;n] (char num date time)=);
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 May 2026 06:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987774#M380073</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-05-13T06:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing a long dataset to wide with multiple variable types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987797#M380075</link>
      <description>&lt;P&gt;Thank you so much for your response!&lt;/P&gt;&lt;P&gt;I am trying to write this code so it an work on any dataset and not just this one.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the example dataset I am using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SID FirstName $ MiddleName $ LastName $ DOB FormName $ FormDateTime Question $ QuestionPosition QuestionType $ Response $&lt;/P&gt;&lt;P&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 This document serves as a guide for care team members to establish, track, and evaluate treatment goals for clients. It aims to facilitate client-centered care and promote collaboration among multidisciplinary team members. Please note that this document should be re-evaluated post-STAIR/post-WET, diagnoses dependent. Please note if a client is on unit longer than a month this document should be reviewed, re-evaluated, and if necessary updated. 1 Information&lt;BR /&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Program Start Date 2 Date 8/1/2025&lt;BR /&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Language conducted in 3 Text - Short English&lt;BR /&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Time In 4 Text - Short 1:00 PM&lt;BR /&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Time Out 5 Text - Short 1:30 PM&lt;BR /&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Date of Treatment Plan Completion 6 Date 8/15/2025&lt;BR /&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Current Revision Date 7 Date 8/15/2025&lt;BR /&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Plan Version # 8 Text - Short 1&lt;BR /&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Duration (rounded to nearest 15-minute interval) 9 Integer (Number) 30&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Target Date for Completion 33 Date 10/31/2025&lt;BR /&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Mental Health Treatment Goals 34 Section header&lt;BR /&gt;999994 Jeff T-Bars 1/1/2000 Project Evolve Treatment Plan 8/15/2025 13:28 Goal 35 Text Client will actively participate&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What variable has the NAME that you want to use for the new variable?&amp;nbsp;:&amp;nbsp;&lt;STRONG&gt;VarName&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;And here is my complete code:&lt;/P&gt;&lt;DIV&gt;/***********************************************&lt;/DIV&gt;&lt;DIV&gt;* 2) Keep ONE form&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;***********************************************/&lt;/DIV&gt;&lt;DIV&gt;data form1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; set longdata;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; where FormName = "Project Evolve Treatment Plan";&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/***********************************************************************&lt;/DIV&gt;&lt;DIV&gt;* 3) Define a metadata map: question text -&amp;gt; variable name + target type&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; target_type: CHAR | DATE | TIME | NUM | CHECK&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; - CHECK will become numeric 0/1&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; - DATE and TIME become numeric SAS date/time with proper formats&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; - CHAR stays character&lt;/DIV&gt;&lt;DIV&gt;***********************************************************************/&lt;/DIV&gt;&lt;DIV&gt;data meta;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; length Question $500 VarName $40 Target_Type $8;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; infile datalines dlm='|' truncover;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; input Question :$500. VarName :$40. Target_Type :$8.;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; datalines;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/****************************************************************************************&lt;/DIV&gt;&lt;DIV&gt;* 4) Clean and standardize unmapped questions and join to metadata&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; - If a question isn't in meta, auto-generate a safe VarName from the question text&lt;/DIV&gt;&lt;DIV&gt;****************************************************************************************/&lt;/DIV&gt;&lt;DIV&gt;proc sql;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; create table joined as&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; select&amp;nbsp; a.*,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; coalesce(b.VarName,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;/* fallback: build a short, SAS-safe name from the question text */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;substr(&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; compress(translate(lowcase(a.Question),'_',' '), , 'kad'),&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1, 32)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;) as VarName length=40,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; upcase(coalesce(b.Target_Type,'CHAR')) as Target_type&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from form1 as a&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; left join meta as b&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; on a.Question = b.Question&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; ;&lt;/DIV&gt;&lt;DIV&gt;quit;&lt;/DIV&gt;&lt;DIV&gt;/*&amp;nbsp; Trying to create a new TARGET_TYPE variable that can identify the right variable type */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc freq data=joined;&lt;/DIV&gt;&lt;DIV&gt;tables QuestionType;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;/* QuestionType:&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Checkbox&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Checkbox header&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Date&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Information&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Integer (Number)&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Section header&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Text&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Text - Short&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;*/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data joined ;&lt;/DIV&gt;&lt;DIV&gt;set joined;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if QuestionType="Date" and flag=0 then TARGET_TYPE="DATE";&lt;/DIV&gt;&lt;DIV&gt;else if QuestionType="Integer (Number)" and flag=0 then TARGET_TYPE="NUM";&lt;/DIV&gt;&lt;DIV&gt;else if QuestionType="Checkbox"&amp;nbsp; and flag=0 then TARGET_TYPE="CHECK";&lt;/DIV&gt;&lt;DIV&gt;else if QuestionType="Text - Short"&amp;nbsp; and flag=1 then TARGET_TYPE="TIME";&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;ELSE;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sort data = joined; by QuestionPosition; run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/****************************************************************************************&lt;/DIV&gt;&lt;DIV&gt;* 5) Normalize Response by Target_Type:&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; - Create RESP_C (character) and RESP_N (numeric) holders&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; - Convert:&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DATE:&amp;nbsp; mm/dd/yyyy -&amp;gt; SAS date&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TIME:&amp;nbsp; e.g., "1:00 PM" -&amp;gt; SAS time&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHECK: Y/N, Yes/No, True/False, 1/0, Checked/Unchecked -&amp;gt; 1/0 numeric&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NUM:&amp;nbsp; &amp;nbsp;numeric parse&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHAR:&amp;nbsp; keep as text&lt;/DIV&gt;&lt;DIV&gt;****************************************************************************************/&lt;/DIV&gt;&lt;DIV&gt;data prepared;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; set joined;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; length RESP_C $1000 RESP_N 8 RESP_DATE 12 RESP_TIME 8;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* retain RESP_C; REMVOING THIS as this retains values over rows, which could be causing the error */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; RESP_C = strip(Response);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; select (upcase(Target_Type));&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when ('DATE') do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RESP_DATE = input(strip(Response), anydtdte.);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; format RESP_DATE date9.;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RESP_C = "";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when ('TIME') do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RESP_TIME = input(strip(Response), anydttme.); /* NA 4/29: timepart is for mixed reponse, so removed it (date + time) */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; format RESP_TIME timeampm.;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RESP_C = "";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when ('CHECK') do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(Response) in ('Y','YES','TRUE','1','CHECKED','Selected') then RESP_N = 1; /* NA 4/29: Added 'Selected' to the list as that is the response of the form */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if missing(Response) then RESP_N = .;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else RESP_N = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /*format RESP_N 1.; */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RESP_C = "";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; when ('NUM') do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RESP_N = input(strip(Response), best32.);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RESP_C = "";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; otherwise do; /* CHAR */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* keep RESP_C */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* 5/6: It is not reading some dates, seems to be only reading Aug 15 correctly but not the other mentioned values */&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This code is resulting in 2 datasets, one containing character values and one containing numeric values which will be merged. However, the numeric dataset has multiple rows per ID due to the different formats.&lt;/DIV&gt;&lt;DIV&gt;proc sort data=prepared;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; by SID FormDateTime;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data prepared;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; set prepared;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; by SID FormDateTime;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; if first.FormDateTime then question_seq = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; question_seq + 1;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data prepared;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; set prepared;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; length VarName_ID $60;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; VarName_ID = cats(VarName, '_Q', put(question_seq, z2.));&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sort data=prepared;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; by SID FormDateTime question_seq;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/***********************************************&lt;/DIV&gt;&lt;DIV&gt;* 6) Sort keys before transposing&lt;/DIV&gt;&lt;DIV&gt;***********************************************/&lt;/DIV&gt;&lt;DIV&gt;proc sort data=prepared;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; by SID FormDateTime FirstName MiddleName LastName DOB;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/***********************************************************************&lt;/DIV&gt;&lt;DIV&gt;* 7) Transpose into wide:&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; - Character targets (CHAR) -&amp;gt; wide_char&lt;/DIV&gt;&lt;DIV&gt;*&amp;nbsp; &amp;nbsp; - Numeric targets (DATE, TIME, NUM, CHECK) -&amp;gt; wide_num&lt;/DIV&gt;&lt;DIV&gt;***********************************************************************/&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc transpose data=prepared(where=(Target_Type='CHAR'))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;out=wide_char(drop=_name_);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; by SID FormDateTime FirstName MiddleName LastName DOB;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; id VarName_ID;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; var RESP_C;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc transpose data=prepared(where=(Target_Type in ('DATE','TIME','NUM','CHECK')))&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;out=wide_num(drop=_name_);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; format RESP_DATE date9. RESP_TIME timeampm.;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; by SID FormDateTime FirstName MiddleName LastName DOB;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; id VarName_ID;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; var RESP_N RESP_DATE RESP_TIME;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;</description>
      <pubDate>Tue, 12 May 2026 14:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987797#M380075</guid>
      <dc:creator>NandiniA</dc:creator>
      <dc:date>2026-05-12T14:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing a long dataset to wide with multiple variable types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987802#M380077</link>
      <description>&lt;P&gt;Remember to use the Insert Code or Insert SAS Code icons on the forum editor when saying text blocks or code blocks.&amp;nbsp; That will prevent the text from being flowed as paragraphs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also when sharing data as text make sure that you have clear delimiters, preferably ones that are visible to humans.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also when sharing a dataset provide a working data step that can recreate the dataset so that other's can make a copy of your data to program from.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards dsd dlm='|' truncover firstobs=2;
  input SID :$9. (FirstName MiddleName LastName) (:$20.)
   DOB :$10. FormName :$32. FormDateTime :anydtdtm. 
   Question :$500. QuestionPosition QuestionType :$30. Response $200.
  ;
  format FormDateTime datetime19.;
cards4;
SID|FirstName|MiddleName|LastName|DOB|FormName|FormDateTime|Question|QuestionPosition|QuestionType|Response|$
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|This document serves as a guide for care team members to establish, track, and evaluate treatment goals for clients. It aims to facilitate client-centered care and promote collaboration among multidisciplinary team members. Please note that this document should be re-evaluated post-STAIR/post-WET, diagnoses dependent. Please note if a client is on unit longer than a month this document should be reviewed, re-evaluated, and if necessary updated.|1|Information
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Program StartDate|2|Date|8/1/2025
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Language conducted in|3|Text - Short|English
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Time In|4|Text - Short|1:00 PM
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Time Out|5|Text - Short|1:30 PM
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Date of Treatment Plan Completion|6|Date|8/15/2025
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Current Revision Date|7|Date|8/15/2025
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Plan Version #|8|Text - Short|1
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Duration (rounded to nearest 15-minute interval)|9|Integer (Number)|30
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Target Date for Completion|33|Date|10/31/2025
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Mental Health Treatment Goals|34|Section header
999994|Jeff||T-Bars|1/1/2000|Project|8/15/2025 13:28|Goal|35|Text|Client will actively participate
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the first thing you need to do is figure out what variables (questions) appear on the form.&amp;nbsp; If you do not have that available directly from the survey metadata then perhaps you can just summarize what you see in the data file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table variables as
 select cats('VAR',put(QuestionPosition,z2.)) as VarName
      , count(*) as nobs
      , QuestionPosition
      , QuestionType
      , Question
 from have
 group by 1,3,4,5
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-05-12 at 11.09.34 AM.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/114957iF70D5314D300C053/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2026-05-12 at 11.09.34 AM.png" alt="Screenshot 2026-05-12 at 11.09.34 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;That should provide most of what you need to create a program to read the actual responses into those variables.&amp;nbsp; But you are missing some information.&amp;nbsp; SAS stores character variables as FIXED length.&amp;nbsp; So you need some way to decide how long to make 5 text variables.&amp;nbsp; Again if they did not provide any metadata that would describe the variables you could try to GUESS a length based on the lengths of the responses in the file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table variables as
 select cats('VAR',put(QuestionPosition,z2.)) as VarName
      , count(*) as nobs
      , max(length(response)) as Length
      , QuestionPosition
      , QuestionType
      , Question
 from have
 group by Varname,QuestionPosition,QuestionType,Question
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also some of those "questions" look more like metadata and not actual user responses.&amp;nbsp; So I doubt that you need to carry Questions number 1 and 34 into the output dataset.&amp;nbsp; In fact question 34 looks like perhaps it should be used to decide what DATASET to create so that you have all of the questions from the same section of the survey in the same SAS dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for this example perhaps you want to generate a data step like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.FormDateTime);
    set have;
    by SID -- FormDateTime ;
    
LENGTH    
 VAR02 8
 VAR03 $8
 VAR04 $8 
 VAR05 $8
 VAR06 8
 VAR07 8
 VAR08 $1
 VAR09 8
 VAR33 8
 VAR35 $40
;
LABEL    
 VAR02 ='Program StartDate'
 VAR03 ='Language conducted in'
 VAR04 ='Time In'
 VAR05 ='Time Out'
 VAR06 ='Date of Treatment Plan Completion'
 VAR07 ='Current Revision Date'
 VAR08 ='Plan Version #'
 VAR09 ='Duration (rounded to nearest 15-minute interval)'
 VAR33 ='Target Date for Completion'
 VAR35 ='Goal'
;
 FORMAT
 VAR02 date9.
 VAR06 date9.
 VAR07 date9.
 VAR33 date9.
;  
 SELECT (QuestionPosition);
   WHEN (2) var02 = input(response,mmddyy10.);
   WHEN (3) var03 = response;
   WHEN (4) var04 = response;
   WHEN (5) var05 = response;
   WHEN (6) var06 = input(response,mmddyy10.);
   WHEN (7) var07 = input(response,mmddyy10.);
   WHEN (8) var08 = response;
   WHEN (9) var09 = input(response,32.);
   WHEN (33) var33 = input(response,mmddyy10.);
   WHEN (35) var35 = response;
   OTHERWISE ;
 END;
   end;
   drop question -- response;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's print the results (using the labels).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print label data=want;
 var SID var: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2026-05-12 at 11.45.03 AM.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/114961iDF3091AE81D3228E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2026-05-12 at 11.45.03 AM.png" alt="Screenshot 2026-05-12 at 11.45.03 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You then just need to work out how to generate that data step from the metadata (or the VARIABLES dataset you generated from the input data).&amp;nbsp; That is not very hard since you can use a data step to write the code to a text file and then just %INCLUDE it to have SAS run it.&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2026 15:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987802#M380077</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-05-12T15:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing a long dataset to wide with multiple variable types</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987817#M380081</link>
      <description>&lt;P&gt;Firstly, I apologize for the formatting. Thank you so much for taking the time to explain this and the detailed response.&lt;/P&gt;&lt;P&gt;The code gave me a wide dataset with the right formats!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will attempt it on the entire dataset now, including the&amp;nbsp;&lt;SPAN&gt;generating the data step from the metadata, and let you know how it goes.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Again, thank you so much!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2026 20:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-a-long-dataset-to-wide-with-multiple-variable-types/m-p/987817#M380081</guid>
      <dc:creator>NandiniA</dc:creator>
      <dc:date>2026-05-12T20:03:03Z</dc:date>
    </item>
  </channel>
</rss>

