<?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: Output freq on multiple vars into one data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968438#M376574</link>
    <description>&lt;P&gt;Are you sure that SEX is one of the variables included in the positional variable list NAME--WEIGHT that you passed to the CATX() function?&amp;nbsp; It should have been created as after the WEIGHT variable in the dataset CLASS you made with your first data step.&amp;nbsp; Run PROC CONTENTS with the VARNUM option to see the actual order of the variables in that dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And even if you did include it in the string you generated with the CATX() function call you put spaces into the values of SEX so that when you later tell scan to use space as one of the multiple characters it considers as a delimiter then it will treat the values of SEX as two separate words .&amp;nbsp; So even if you did find the value of SEX the values like&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;(a1) F&lt;/LI-CODE&gt;
&lt;P&gt;will only return (a1) from the SCAN() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why are you using CATX() and SCAN() here at all?&amp;nbsp; That should not work properly for a number of reasons.&amp;nbsp; First the CATX() function ignores the missing values when generating the string.&amp;nbsp; Second only one of the variables should have a none missing value, ten one whose name you just found in the previous statement.&amp;nbsp; You might just use CATS() instead?&amp;nbsp; But why not just use VVALUEX() to find the value of the variable whose name you just got?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;v_name=scan(table,2);
v_value=vvaluex(v_name);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jun 2025 12:16:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-06-09T12:16:30Z</dc:date>
    <item>
      <title>Output freq on multiple vars into one data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968431#M376569</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to do freq on multiple vars.&lt;/P&gt;
&lt;P&gt;What is the reason that for var sex (the var that i defined) I dont see values in resulted data set???&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA CLASS(drop=sex rename=(_sex=sex));
SET sashelp.class;
IF SEX='F' THEN _SEX='(a1) F';
else _Sex='(a2) M';
Run;

ods output onewayfreqs=work.owf;
proc freq data=CLASS ;
tables _all_/nocum nopercent ;
run;
data work.owf(drop=frequency) ;
set work.owf ;
count=frequency;
run;
data work.owf;
length v_name v_value $ 200;
set work.owf;
v_name=scan(table,2);
v_value=scan(catx(' ',of name--weight),1);
*name is the first variable,weight is the last variable in sashelp.class table;
keep v_name v_value count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Jun 2025 10:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968431#M376569</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-06-09T10:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Output freq on multiple vars into one data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968434#M376571</link>
      <description>&lt;P&gt;To simplify the whole program&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods output onewayfreqs=work.owf(rename=(frequency=count));
proc freq data=sashelp.CLASS ;
tables _all_/nocum nopercent ;
run;

data work.owf2;
length v_name v_value $ 200;
set work.owf;
v_name=scan(table,2);
v_value=scan(catx(' ',of sex name--weight ),1,' ');
*name is the first variable,weight is the last variable in sashelp.class table;
keep v_name v_value count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I ask what is the reason why you are complicating things by creating new sexes '(a1) F' and '(a2) M' ? I have never heard of these, I'm sure most people don't know what these cryptic codes a1 and a2 mean, so I have left these out of the solution. If you really need them, put them back into my code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another simplification would be not to rename FREQUENCY to COUNT, I don't see the point of taking the time to do that either, but you don't need a DATA step to do that rename.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 11:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968434#M376571</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-06-09T11:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Output freq on multiple vars into one data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968436#M376572</link>
      <description>&lt;P&gt;The value of the Sex variable is blank because of this statement:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;v_value=scan(catx(' ',of name--weight),1);
*name is the first variable,weight is the last variable in sashelp.class table;&lt;/LI-CODE&gt;
&lt;P&gt;Weight is not the last variable in the data set since you created _sex and then renamed it to Sex. You either need to use name--sex, or I would suggest the following revised code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.owf1;
retain v_name v_value;
length v_name v_value $ 200;
set work.owf;
v_name=scan(table,2);
v_value=trim(left(vvaluex(v_name)));*catx(' ',of name--sex);
*name is the first variable,weight is the last variable in sashelp.class table;
keep v_name v_value count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Jun 2025 12:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968436#M376572</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-06-09T12:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Output freq on multiple vars into one data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968437#M376573</link>
      <description>&lt;P&gt;Good point&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13770"&gt;@Kathryn_SAS&lt;/a&gt;&amp;nbsp;, adding VVALUEX into the code is a much better way to go here.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 12:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968437#M376573</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-06-09T12:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Output freq on multiple vars into one data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968438#M376574</link>
      <description>&lt;P&gt;Are you sure that SEX is one of the variables included in the positional variable list NAME--WEIGHT that you passed to the CATX() function?&amp;nbsp; It should have been created as after the WEIGHT variable in the dataset CLASS you made with your first data step.&amp;nbsp; Run PROC CONTENTS with the VARNUM option to see the actual order of the variables in that dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And even if you did include it in the string you generated with the CATX() function call you put spaces into the values of SEX so that when you later tell scan to use space as one of the multiple characters it considers as a delimiter then it will treat the values of SEX as two separate words .&amp;nbsp; So even if you did find the value of SEX the values like&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;(a1) F&lt;/LI-CODE&gt;
&lt;P&gt;will only return (a1) from the SCAN() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But why are you using CATX() and SCAN() here at all?&amp;nbsp; That should not work properly for a number of reasons.&amp;nbsp; First the CATX() function ignores the missing values when generating the string.&amp;nbsp; Second only one of the variables should have a none missing value, ten one whose name you just found in the previous statement.&amp;nbsp; You might just use CATS() instead?&amp;nbsp; But why not just use VVALUEX() to find the value of the variable whose name you just got?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;v_name=scan(table,2);
v_value=vvaluex(v_name);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 12:16:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968438#M376574</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-09T12:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Output freq on multiple vars into one data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968439#M376575</link>
      <description>&lt;P&gt;Why would you include the TRIM() function in this statement?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;v_value=trim(left(vvaluex(v_name)));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;SAS will just append the trailing spaces back onto the value when you store it into the fixed length variable V_VALUE.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jun 2025 12:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968439#M376575</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-09T12:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Output freq on multiple vars into one data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968445#M376576</link>
      <description>You are right that TRIM is not necessary. I am just in the habit of using both when aligning numeric and character values in a column. Thanks for pointing that out!</description>
      <pubDate>Mon, 09 Jun 2025 12:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968445#M376576</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-06-09T12:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: Output freq on multiple vars into one data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968500#M376588</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;This code work well&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA CLASS(drop=sex rename=(_sex=sex));
SET sashelp.class;
IF SEX='F' THEN _SEX='(a1) F';
else _Sex='(a2) M';
Run;

ods output onewayfreqs=freq_tbl1;
proc freq data=CLASS ;
tables _all_  /**Name Age   Height   Weight    Sex**//nocum  ;
run;

ods output close;  *technically unneeded but makes it more clear;
data freq_tbl2(KEEP=var_name value Frequency Percent);
retain var_name value Frequency Percent;
set freq_tbl1;
value = left(coalescec(of f_:));
var_name=scan(table,2); /**Take second word from field table**/
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Jun 2025 05:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Output-freq-on-multiple-vars-into-one-data-set/m-p/968500#M376588</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-06-10T05:00:28Z</dc:date>
    </item>
  </channel>
</rss>

