<?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 Multiple datasets reshape and calculate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872687#M344769</link>
    <description>I have multiple longitudinal datasets. I want to transpose by one variable each of those datasets. The variable has 6 categories—then calculate the average weight (numeric data) by groups for each column (6 above categories). &lt;BR /&gt;How can I do that? Better a macro that I can change dataset name, transposing variable (this variable name is different for each dataset), and the weight (sometime the weight is as numeric and sometimes as character and the name is different —sometime weight and sometimes wgt). Thank you.</description>
    <pubDate>Thu, 27 Apr 2023 20:55:50 GMT</pubDate>
    <dc:creator>Emma2021</dc:creator>
    <dc:date>2023-04-27T20:55:50Z</dc:date>
    <item>
      <title>Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872687#M344769</link>
      <description>I have multiple longitudinal datasets. I want to transpose by one variable each of those datasets. The variable has 6 categories—then calculate the average weight (numeric data) by groups for each column (6 above categories). &lt;BR /&gt;How can I do that? Better a macro that I can change dataset name, transposing variable (this variable name is different for each dataset), and the weight (sometime the weight is as numeric and sometimes as character and the name is different —sometime weight and sometimes wgt). Thank you.</description>
      <pubDate>Thu, 27 Apr 2023 20:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872687#M344769</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-27T20:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872688#M344770</link>
      <description>&lt;P&gt;If you are computing means, it seems like you want a report rather than a reshaped data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Providing a portion of your data would help as then I (and others) could provide actual code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't have a weight that is character.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 21:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872688#M344770</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-27T21:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872695#M344772</link>
      <description>No report, but creating person level weight data from multiple time measured weights.</description>
      <pubDate>Thu, 27 Apr 2023 21:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872695#M344772</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-27T21:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872707#M344777</link>
      <description>&lt;P&gt;Looks like you need just average weight of all subjects per timepoint. Does sashelp.cars example reflects your data?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table want as 
		select *, mean(weight) as Average
			from sashelp.cars
		group by type
	order by type;
quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the weight comes as character datatype (which is abnormal), use "mean(input(weight, best.)) as Average".&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 23:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872707#M344777</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-04-27T23:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872718#M344783</link>
      <description>No. For example, there are 5 doctors who took the weight measure - each doctor took multiple times. So, first it has to be reshaped by those doctors as wide and then calculate average weight for each doctor. So-it has to be reshaped first. Also, I prefer macro since there are many datasets (with 3 parameters as I mentioned). Thank you!</description>
      <pubDate>Fri, 28 Apr 2023 01:33:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872718#M344783</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-28T01:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872721#M344784</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;So, first it has to be reshaped &lt;STRONG&gt;by those doctors&lt;/STRONG&gt; as wide...&lt;/SPAN&gt;"&lt;/P&gt;
&lt;P&gt;That's exactly what SAS BY processing is for. Have a look into Proc Means. You would have the doctor variable either in the CLASS or BY statement.&lt;/P&gt;
&lt;P&gt;With Proc SQL similar things can be done using the GROUP BY statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's most of the time better to keep the data in a narrow structure.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 02:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872721#M344784</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-04-28T02:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872722#M344785</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;No. For example, there are 5 doctors who took the weight measure - each doctor took multiple times. So, first it has to be reshaped by those doctors as wide and then calculate average weight for each doctor. So-it has to be reshaped first. Also, I prefer macro since there are many datasets (with 3 parameters as I mentioned). Thank you!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please go back to your first post. Read it closely.&lt;/P&gt;
&lt;P&gt;Do you see any mention of DOCTOR? I don't. When you do not accurately describe the data (HINT: provide actual data) and a clear description of all of the elements of a task it doesn't help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to have the mean of some measures by the combination of Doctor and "person" then Proc Means/ summary with a class statement will do that. No reason to make a wide data set. &lt;/P&gt;
&lt;P&gt;Here is a brief example of calculating a few means by groups of other variables with a data set that you should have in your SAS install.&lt;/P&gt;
&lt;PRE&gt;Proc summary data=sashelp.class;
   class sex age;
   var height weight;
   output out=example mean= ;
run;&lt;/PRE&gt;
&lt;P&gt;The above calculates the means for 1)all observations in the data set 2)each level of age 3) each level of sex and 4) each combination of sex and age present in the data. Note that there are two variables in the output also added: _freq_, which is the number of observations used for each record and _type_ which aligns with which combination.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I show how to do multiple because your description changes. You can select which one makes sense for your specific use by selecting the correct _type_ value. IF you want the combinations of Sex and Age, which would be _type_=3 you could add the option NWAY to the Proc statement. Think of Sex as taking the role of your Doctor variable and Age as the person id.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; said, a variable used to weight data cannot be character. In the case that you actually have a variable that should be treated as a weighting variable then when you fix the character issue fix &lt;STRONG&gt;all &lt;/STRONG&gt;the name issues as well. You would have to do this before any "macro" to begin with.&lt;/P&gt;
&lt;P&gt;If your data sets are similar enough otherwise then perhaps they should be combined before this summary. Unless there is yet another level of the problem you have not described. I would be wondering if some combinations of Doctor and person occur in different data sets (perhaps different time periods????) and should there be separate "means" just because they occur in different data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cleaning data to standardize things like variable names, types and lengths is something that should be done before any analysis or reporting. Try it. You'll find that everything goes much smoother later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 02:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872722#M344785</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-28T02:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872765#M344807</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;No report, but creating person level weight data from multiple time measured weights.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC SUMMARY can create a data set with averages by person (or even by multiple categories), but still you cannot have weights unless they are numeric. This is an absolute restriction, weights must be numeric.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 10:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872765#M344807</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-28T10:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872767#M344809</link>
      <description>The datasets are long formatted by id and doctor type. The weight variable has to be averaged by doctor type but not long formatted -has to be wide formatted ( doctor types should be columns and IDs are as rows. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Note: I would like a macro since  there are many are many datasets,&lt;BR /&gt;Doctor type variable not consistently named across all datasets as well as the weight variable.</description>
      <pubDate>Fri, 28 Apr 2023 10:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872767#M344809</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-28T10:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872768#M344810</link>
      <description>&lt;P&gt;Please show us a portion of one of these data sets. If the data is confidential, please make up a data set that represents the real problem. Please provide the data as working SAS data step code, which you can type in your self, or you can follow &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. Do &lt;FONT color="#FF0000"&gt;not&lt;/FONT&gt; provide the data in any other form. REPEATING: DO &lt;FONT color="#FF0000"&gt;NOT&lt;/FONT&gt; PROVIDE THE DATA IN ANY OTHER FORM.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 10:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872768#M344810</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-28T10:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872797#M344818</link>
      <description />
      <pubDate>Fri, 28 Apr 2023 18:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872797#M344818</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-28T18:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872804#M344819</link>
      <description>&lt;P&gt;Use PROC SUMMARY to count/average.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID :$13. Doctor :$8. Wgt;
datalines4;
Acura MDX 3.5
Acura MDX 5.5
Acura RSX 2 4
Acura RSX 2 4
Acura TS 4.4
Acura TS 6.4
Acura TL 6.2
Kin MDX 3.5
Kin MDX 5.5
Kin RSX 2 4
Kin RSX 2 4
Kin TS 4.4
Kin TS 6.4
Kin TL 6.2
Kin TL 3.5
;;;;

proc summary data=have nway ;
  class id doctor;
  var wgt ;
  output out=step1 mean= ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then use PROC TRANSPOSE to convert to wide&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=step1 out=weights ;
  by id;
  id doctor;
  var wgt ;
run;

proc transpose data=step1 out=counts prefix=num_;
  by id;
  id doctor;
  var _freq_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use a format to display the counts larger than 1 as YES.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value multiple
    low-1 = 'NO'
    2-high = 'YES'
  ;
run;

data want;
  merge weights counts;
  by id;
  drop _name_;
  format num_: multiple.;
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="Tom_0-1682690294853.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83370iE293018A4AA15606/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1682690294853.png" alt="Tom_0-1682690294853.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 13:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872804#M344819</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T13:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872810#M344821</link>
      <description>Thank you. I need a sas macro to loop over multiple datasets.</description>
      <pubDate>Fri, 28 Apr 2023 14:09:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872810#M344821</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-28T14:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872816#M344824</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you. I need a sas macro to loop over multiple datasets.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Macro code is used to generate SAS code (in general).&amp;nbsp; So first figure out what SAS code you need to generate for one input.&amp;nbsp; Then clarify what parts of that code will need to change to handle a different dataset.&amp;nbsp; Replace those parts with macro variables.&amp;nbsp; Get that to work.&amp;nbsp; Then wrap the result into a macro that uses those macro variables as the input parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you have multiple datasets?&lt;/P&gt;
&lt;P&gt;What do they represent?&lt;/P&gt;
&lt;P&gt;How are they different?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the structure of each dataset is the same then perhaps you just need to first combine them into one dataset and then run the same code as before only adding an extra BY/CLASS variable before ID.&amp;nbsp; At that point I am not sure how much value is added by converting the program into a macro.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872816#M344824</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T14:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872819#M344825</link>
      <description />
      <pubDate>Fri, 28 Apr 2023 18:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872819#M344825</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-28T18:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872822#M344827</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have received many Datasets that I need to create separate datasets from long to wide (maybe different hospitals).&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Combine the datasets.&amp;nbsp; Assuming there is already a variable that indicates the hospital.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all;
  set hospital1 hospital2 ...... ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now just add HOSPITAL in addition to ID and DOCTOR as the CLASS variables.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:26:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872822#M344827</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T14:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872825#M344828</link>
      <description />
      <pubDate>Fri, 28 Apr 2023 19:00:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872825#M344828</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-28T19:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872827#M344830</link>
      <description />
      <pubDate>Fri, 28 Apr 2023 19:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872827#M344830</guid>
      <dc:creator>Emma2021</dc:creator>
      <dc:date>2023-04-28T19:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872830#M344833</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I need 3 parameters:&lt;BR /&gt;Input and output dataset name (added suffix such as 1 and 2 is fine), by variable to transpose, and variable (for car). &lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Take the existing code that works for ONE dataset.&amp;nbsp; Say it is reading in from dataset HOSP1 and writing out dataset WANT1.&amp;nbsp; Say the variable names that change are called ID and DOCTOR.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So take you code that works and replace every reference to HOSP1 with &amp;amp;INDSN&amp;nbsp; and every reference to WANT1 with &amp;amp;OUTDSN.&amp;nbsp; Do same thing for the variable names.&amp;nbsp; Then add these four %LET statements before the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let indsn=HOSP1;
%let outdsn=WANT1;
%let var1=ID;
%let var2=DOCTOR;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And run it again.&amp;nbsp; Get it to work.&lt;/P&gt;
&lt;P&gt;Now add a %MEND statement after the code.&amp;nbsp; Replace the %LET statements with this %MACRO statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro mymacro(indsn,outdsn,var1,var2);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After the %MEND statement add this call to the macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%mymacro(indsn=HOSP1,outdsn=WANT1,var1=ID,var2=DOCTOR)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;RUn it and get it to work.&lt;/P&gt;
&lt;P&gt;Now to run other datasets just replicate the macro call and change the input dataset and output dataset names and if needed the variable names.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872830#M344833</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-28T14:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple datasets reshape and calculate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872832#M344835</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/381519"&gt;@Emma2021&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;No -should not combine -they should be separate and outputs datasets should be separate&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Include a "hospital" variable, which could be the source dataset name when combining data.&lt;/P&gt;
&lt;P&gt;Then in proc summary include that variable as a class (or if the resulting data set is large enough a BY variable)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And even with multiple hospitals/treatment facilities you can still have the same doctor see the same patient. So you still need to consider how those cases are to be considered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Really, &lt;STRONG&gt;fix the data.&lt;/STRONG&gt; Make sure the data sets have the same variable names, properties and types. THEN do any analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your insistence on a loopy macro trying to handle different variable names, changing types (your claim the weight/wgt variable is sometimes character) is a &lt;STRONG&gt;symptom&lt;/STRONG&gt;, not a solution. If really needed, and no actual need has been demonstrated, after the summary step you can separate the data into different sets. And then any processing of those further data sets will &lt;STRONG&gt;much easier &lt;/STRONG&gt;because then all the variables are the same and the same type. Otherwise you get to go through the same nonsense all over again to deal with each new summarized data set. Unless the whole purpose of specifying this macro approach is to create some sort of job security because no one else will be able to follow what was done and why...&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 14:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-datasets-reshape-and-calculate/m-p/872832#M344835</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-04-28T14:37:54Z</dc:date>
    </item>
  </channel>
</rss>

