<?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: how can I do the same action for all variables in the dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695211#M212113</link>
    <description>I will have to export this into Excel worksheet later on, so no report needed at this stage</description>
    <pubDate>Thu, 29 Oct 2020 14:33:49 GMT</pubDate>
    <dc:creator>Sas_user987</dc:creator>
    <dc:date>2020-10-29T14:33:49Z</dc:date>
    <item>
      <title>how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695201#M212106</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like your advice on how to deal with this as I cant figure this our my self.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently have around 600 variables in SAS table. What I want to do is to show unique value in each column and proportion of each value in the column (whether its number of rows, exposure or any other way of measuring).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In python I would simply add all columns in to the list and then do the "for" loop, asking python to do the same action for every i in the list.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I achieve the same in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to be clear, I am looking for a way to do the same action for every variable in SAS table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks,&lt;/P&gt;&lt;P&gt;J&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S. Im using SAS 8.1&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 14:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695201#M212106</guid>
      <dc:creator>Sas_user987</dc:creator>
      <dc:date>2020-10-29T14:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695207#M212111</link>
      <description>&lt;P&gt;Do you want this in a report of some sort or in a SAS data set?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 14:31:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695207#M212111</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-10-29T14:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695211#M212113</link>
      <description>I will have to export this into Excel worksheet later on, so no report needed at this stage</description>
      <pubDate>Thu, 29 Oct 2020 14:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695211#M212113</guid>
      <dc:creator>Sas_user987</dc:creator>
      <dc:date>2020-10-29T14:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695220#M212118</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344589"&gt;@Sas_user987&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like your advice on how to deal with this as I cant figure this our my self.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I currently have around 600 variables in SAS table. What I want to do is to show unique value in each column and proportion of each value in the column (whether its number of rows, exposure or any other way of measuring).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In python I would simply add all columns in to the list and then do the "for" loop, asking python to do the same action for every i in the list.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could I achieve the same in SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to be clear, I am looking for a way to do the same action for every variable in SAS table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks,&lt;/P&gt;
&lt;P&gt;J&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="6"&gt;&lt;STRONG&gt;P.S. Im using SAS 8.1&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Really, you need to provide some example data, probably 10 rows and 5 variables would suffice. Then show the expected results for that output.&lt;/P&gt;
&lt;P&gt;If you don't know how to write a data step from data:&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; 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 &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your requirement of "What I want to do is to show unique value in each column and proportion of each value in the column " is actually much easier in one of the report procedures but what you expect for appearance is critical.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The approach that SAS uses for manually written processes for "each variable" would be an array but you cannot mix variable types in an array. So actual content matters and desired appearance is critical.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps you want:&lt;/P&gt;
&lt;PRE&gt;Proc freq data=yourdatasetname;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which will create a separate table for each variable with the count, percent of records, cumulative count and cumulative percent plus and indicator for the number of missing values.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 15:25:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695220#M212118</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-29T15:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695221#M212119</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To perform the same action on all columns of a dataset, you can use call vnext in a loop&lt;/P&gt;
&lt;P&gt;as follows :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dosomething(varname);

    variable=&amp;amp;varname.;
    value=vvaluex(&amp;amp;varname.); 
    put _N_= variable= value=;

%mend dosomething;

data _NULL_;
    set sashelp.class;
    length _NAME_ $32.;

    do while(_NAME_ ne "_NAME_");
        call vnext(_NAME_);
        if _NAME_ ne "_NAME_" then do;
            %dosomething(_NAME_);
        end;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also use arrays but you will have to duplicate your loop if the dataset&lt;/P&gt;
&lt;P&gt;contains character as well as numeric columns.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 15:02:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695221#M212119</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-10-29T15:02:38Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695233#M212123</link>
      <description>&lt;P&gt;PROC FREQ piped to ODS EXCEL is the simplest method, each variable goes to it's own worksheet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods excel file = "/home/fkhurshed/example.xlsx" options(sheet_interval = "table");

proc freq data=sashelp.class;
run;

ods excel close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI - you're likely not on SAS 8.1 (it's over 20+ years old) but on EG 8.1? You can find your SAS version by running the following and checking the log afterwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc product_status;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344589"&gt;@Sas_user987&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like your advice on how to deal with this as I cant figure this our my self.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I currently have around 600 variables in SAS table. What I want to do is to show unique value in each column and proportion of each value in the column (whether its number of rows, exposure or any other way of measuring).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In python I would simply add all columns in to the list and then do the "for" loop, asking python to do the same action for every i in the list.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could I achieve the same in SAS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just to be clear, I am looking for a way to do the same action for every variable in SAS table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks,&lt;/P&gt;
&lt;P&gt;J&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. Im using SAS 8.1&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 15:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695233#M212123</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-29T15:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695251#M212135</link>
      <description>&lt;P&gt;Thanks everyone for your responds.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So currently I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc summary data=datatouse nway;
class varname1;
var measurevar;
output out=varname1 (drop=_FREQ_ _TYPE_ rename=(measurevar=ex_varname1)) sum=;
run;&lt;/PRE&gt;&lt;P&gt;the reason im using proc summary instead of proc freq is so i could use exposure as a measuring variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The idea later is to have one excel sheet with all variables which would allow for quick search later on.&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;varname1&lt;/TD&gt;&lt;TD&gt;ex_varname1&lt;/TD&gt;&lt;TD&gt;varname2&lt;/TD&gt;&lt;TD&gt;ex_varname2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;unique_val1&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;unique_val1&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;unique_val2&lt;/TD&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;TD&gt;unique_val2&lt;/TD&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;missing&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would usually write a macro for this and call a macro for each variable, but when there are 600 variables its hard to understand what is happening in the SAS file itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want SAS automatically perform summary to every variable in the dataset without specifically naming it, so i do need to find a way&amp;nbsp; to change varname1 to varname2 etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will later need to take all these var names and stick it into one big table. Hence I was thinking about something similar to python lists, as I will need var names in later stages.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;J&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S. sas eg 8.1&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sas_user987_0-1603987747449.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51214i92772CA1796961EF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sas_user987_0-1603987747449.png" alt="Sas_user987_0-1603987747449.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 16:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695251#M212135</guid>
      <dc:creator>Sas_user987</dc:creator>
      <dc:date>2020-10-29T16:55:06Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695253#M212136</link>
      <description>&lt;P&gt;I doubt you are using 8.1, that was released 20 years ago.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2013/08/02/how-old-is-your-version-of-sas-release-dates-for-sas-software.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2013/08/02/how-old-is-your-version-of-sas-release-dates-for-sas-software.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To see what version check the automatic macro variable SYSVLONG.&lt;/P&gt;
&lt;PRE&gt;87    %put &amp;amp;=sysvlong;
SYSVLONG=9.04.01M5P091317
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 16:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695253#M212136</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-29T16:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695255#M212137</link>
      <description>&lt;P&gt;You can use the special _ALL_ variable list.&lt;/P&gt;
&lt;P&gt;So if your existing dataset is named HAVE you could use this code to produce frequency tables for every variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
  tables _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Oct 2020 16:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695255#M212137</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-29T16:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695265#M212144</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344589"&gt;@Sas_user987&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks everyone for your responds.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So currently I have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc summary data=datatouse nway;
class varname1;
var measurevar;
output out=varname1 (drop=_FREQ_ _TYPE_ rename=(exposure=ex_varname1)) sum=;
run;&lt;/PRE&gt;
&lt;P&gt;the reason im using proc summary instead of proc freq is so i could use exposure as a measuring variable.&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Makes no sense. You aren't using "exposure" anywhere in the body of the proc summary code so it does not exist for output and no "ex_varname1" would be created but you will get a warning&lt;/P&gt;
&lt;PRE&gt;WARNING: The variable exposure in the DROP, KEEP, or RENAME
         list has never been referenced.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And to tell the truth, the appearance of the desired output does not appear to be "easy to search" in any form.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 16:40:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695265#M212144</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-29T16:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695270#M212149</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I edited my code to have measurevar instead of exposure. Hopefully makes more sense now.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Thu, 29 Oct 2020 16:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695270#M212149</guid>
      <dc:creator>Sas_user987</dc:creator>
      <dc:date>2020-10-29T16:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695278#M212152</link>
      <description>&lt;P&gt;Why do you need the RENAME= option? Without that your code runs fine.&amp;nbsp; Just list the variables you want in the VAR statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=datatouse nway;
  class varname1;
  var _numeric_;
  output out=varname1 (drop=_FREQ_ _TYPE_) sum=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you must have different names for the new variables use the /AUTONAME option in the OUTPUT statement.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 17:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695278#M212152</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-29T17:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695284#M212157</link>
      <description>Are you trying to do something like this:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Demographic-Table-and-Subgroup-Summary-Macro-TABLEN/ta-p/634030" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Demographic-Table-and-Subgroup-Summary-Macro-TABLEN/ta-p/634030&lt;/A&gt;</description>
      <pubDate>Thu, 29 Oct 2020 17:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695284#M212157</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-29T17:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695285#M212158</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You can use the special _ALL_ variable list.&lt;/P&gt;
&lt;P&gt;So if your existing dataset is named HAVE you could use this code to produce frequency tables for every variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
  tables _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you need the counts be the "sum" of some other variable use the WEIGHT statment.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
  tables varname1-varname600;
  weight measurement;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Oct 2020 17:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695285#M212158</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-29T17:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695286#M212159</link>
      <description>in this case I am using same measuring variable to measure varname1, varname2 etc. If i dont change measurevar into ex_varname1, ex_varname2, in later stages when I want to stick everything into one big table later on, I would end up with same var name (the measurevar).</description>
      <pubDate>Thu, 29 Oct 2020 17:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695286#M212159</guid>
      <dc:creator>Sas_user987</dc:creator>
      <dc:date>2020-10-29T17:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695288#M212160</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344589"&gt;@Sas_user987&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;in this case I am using same measuring variable to measure varname1, varname2 etc. If i dont change measurevar into ex_varname1, ex_varname2, in later stages when I want to stick everything into one big table later on, I would end up with same var name (the measurevar).&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sounds like you want to use measurevar as a WEIGHT.&amp;nbsp; See my example using PROC FREQ.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 17:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695288#M212160</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-29T17:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695453#M212228</link>
      <description>&lt;P&gt;What you are looking for is IML code .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc iml;
use sashelp.heart nobs nobs;
read all var _char_ into x[c=vname];
close;
do i=1 to ncol(x);
  call tabulate(level,freq,x[,i]);
  level=t(level);
  freq=t(freq);
  percent=freq/nobs;
  print level[c=(vname[i]) l=''] freq percent[f=percent8.2];
end;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Oct 2020 12:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695453#M212228</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-10-30T12:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695511#M212246</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for this, this looks very advanced. I tried your solution, but it doesn't work and I can not fix it because I don't really understand it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After whole day of research and testing, I finally ended up somewhere (but there's still a long way to go at this pace).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all I run proc contents&amp;nbsp; to get the variable names:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;proc contents data=have1 noprint out=col_name (keep=name); run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then run the following statement to put those vars in some kind of macro i guess?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Proc sql;
select * into :vars_to_run from col_name;
quit;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And finally i get to the stage where I could calculate proc freq for every var in the dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;%macro test;
    %do i=1 %to %sysfunc(countw(&amp;amp;variables_to_run));
    proc freq data=have1;
    tables var_name / norow nocol nopercent nocum missing out=var_name;
    weight measurevar;
    %end;
    run;
%mend;
%test;

var_name - system should automatically select all available variables in the dataset&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just need to find a way of telling SAS to run this for every var in the dataset and output as a separate dataset with var_name as a table name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;J&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 15:25:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695511#M212246</guid>
      <dc:creator>Sas_user987</dc:creator>
      <dc:date>2020-10-30T15:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695515#M212248</link>
      <description>&lt;P&gt;You do know that _all_ refers to all variables? It has specific uses but works for what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   ods output onewayfreq = want;
    proc freq data=have1;
    tables _all_ / norow nocol nopercent nocum missing ;
    weight measurevar;
    run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is a reference that illustrates how to refer to variables and datasets in a short cut list:&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An alternative option is this which does it all at once, no macro and pipes them all to a single data set. Change&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Run frequency for tables;
ods table onewayfreqs=temp;
proc freq data=sashelp.class;
	table _all_;
weight age;
run;

*Format output;
data want;
length variable $32. variable_value $50.;
set temp;
Variable=scan(table, 2);

Variable_Value=strip(trim(vvaluex(variable)));

keep variable variable_value frequency percent cum:;
label variable='Variable' 
	variable_value='Variable Value';
run;

*Display;
proc print data=want(obs=20) label;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344589"&gt;@Sas_user987&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for this, this looks very advanced. I tried your solution, but it doesn't work and I can not fix it because I don't really understand it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After whole day of research and testing, I finally ended up somewhere (but there's still a long way to go at this pace).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all I run proc contents&amp;nbsp; to get the variable names:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;proc contents data=have1 noprint out=col_name (keep=name); run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I then run the following statement to put those vars in some kind of macro i guess?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Proc sql;
select * into :vars_to_run from col_name;
quit;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And finally i get to the stage where I could calculate proc freq for every var in the dataset&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;%macro test;
    %do i=1 %to %sysfunc(countw(&amp;amp;variables_to_run));
    proc freq data=have1;
    tables var_name / norow nocol nopercent nocum missing out=var_name;
    weight measurevar;
    %end;
    run;
%mend;
%test;

var_name - system should automatically select all available variables in the dataset&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just need to find a way of telling SAS to run this for every var in the dataset and output as a separate dataset with var_name as a table name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;J&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 15:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695515#M212248</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-30T15:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: how can I do the same action for all variables in the dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695523#M212252</link>
      <description>&lt;P&gt;Not sure why want to complicate your program instead of just using the existing functionality of SAS.&amp;nbsp; Why would you want to read through the input datasets over and over again instead of generating all of the data in one pass? Why would you want to generate a separate dataset for each input variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way to think about how to something for every variable is to restructure the data.&amp;nbsp; So if you have a unique id you could just use PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have1 
  out=tall(rename=(col1=VALUE)
           where=(upcase(_name_) not in ('ID','MEASUREVAR')
          ) 
;
  by ID MEASUREVAR;
  var _all_;
run;
proc freq data=tall;
  tables _NAME_*VALUE / norow nocol nopercent nocum missing out=WANT;
  weight measurevar;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note this might not work so well with a lot of distinct values.&amp;nbsp; So it might help to sort the TALL dataset first and then use BY processing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=tall;
  by _name_;
run;
proc freq data=tall;
  by _name_;
  tables VALUE / norow nocol nopercent nocum missing out=WANT;
  weight measurevar;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It does not sound like you know enough about what SAS code you want to run to begin trying to use macro code to generate SAS code.&amp;nbsp; But if you did want to build a macro to do something for every variable in a dataset then here are some pointers.&amp;nbsp;First make sure to parameterize your macro properly.&amp;nbsp; In this case I would make the name of the DATASET the parameter to the macro and possibly also the name of the variable being summed.&amp;nbsp; Second if you use the method of sticking variable names into a single macro variable remember that macro variables have a limit of 64k bytes so there will be a limit to the number of variables the macro could handle. So if the variable names are all 31 characters long it could fit 2K variable names. If they are all 7 characters long then it could fit 8K variable names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The specific mistakes your current code has are:&lt;/P&gt;
&lt;P&gt;You only put one name into the macro variable.&amp;nbsp; And you should eliminate MEASUREVAR from the list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select name into :vars_to_run separated by ' ' from col_name
  where upcase(name) ne 'MEASUREVAR'
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You never actually pull out the next name from the list and use it to generate the code you want to run.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to %sysfunc(countw(&amp;amp;variables_to_run));
proc freq data=have1;
  %let var=%scan(&amp;amp;variables_to_run,&amp;amp;i,%str( ));
  tables &amp;amp;var  / norow nocol nopercent nocum missing out=&amp;amp;var;
  weight measurevar;
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 16:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-I-do-the-same-action-for-all-variables-in-the-dataset/m-p/695523#M212252</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-30T16:33:14Z</dc:date>
    </item>
  </channel>
</rss>

