<?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: Create a Label dataset as sample below in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866601#M342239</link>
    <description>I would like to create a certain format Table.  N column is not the final variable, it actually a N+PCN, and format is like "N(%)"</description>
    <pubDate>Mon, 27 Mar 2023 18:31:15 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2023-03-27T18:31:15Z</dc:date>
    <item>
      <title>Create a Label dataset as sample below</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866593#M342235</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a Tabulate output dataset as listed below.&amp;nbsp; I created an individual data step as Macro below.&amp;nbsp; I would like to combine three datasets, Age/Sex/Race, the similar result as Want_1 or Want_2 below.&amp;nbsp; Is there a way to do it?&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
	value race 1='White-NH' 2='Black/African American-NH' 3='Non-Hispanic other' 4='Hispanic';
	value Age 1='2-4 years' 2='5-11 years' 3='12-17 years';
	value Sex 1='Male' 2='Female';
run;

data Tabulate_Output;
Format Age Age. race race. Sex Sex.;
input Age  Sex  Race  N;
infile datalines delimiter='/';
datalines;
1/././261/
2/././283/
3/././130/
./1/./799/
./2/./117/
././1/220/
././2/111/
././3/55/
;
run;

%Macro A (Var);
data &amp;amp;Var.;
	set Tabulate_Output;
	if &amp;amp;Var. ^=.;
	keep &amp;amp;Var. N;
run;
%mend;
%A (Age);
%A (Sex);
%A (Race);

data Want_1;
input  N Demo $;
infile datalines delimiter='/';
datalines;
261/Age_1
283/Age_2
130/Age_3
799/Sex_1
117/Sex_2
220/Race_1
111/Race_2
55/Race_3
;
run;

data Want_2;
input N Demo $;
infile datalines delimiter='/';
datalines;
261/Age_2-4y
283/Age_5-11y
130/Age_12-17y
799/Sex_M
117/Sex_F
220/Race_White
111/Race_Black
55/Race_Other
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Mar 2023 18:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866593#M342235</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-27T18:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Label dataset as sample below</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866595#M342237</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;please take this as constructive criticism ... this strikes me as something an experienced programmer would avoid doing, but less experienced programmers want to do. I see little value here, and a PROC PRINT of data set Tabulate_Output would achieve the same display of the data. So, I recommend you don't do this without a VERY good reason. (Okay, why do you want to do this???)&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 18:10:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866595#M342237</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-27T18:10:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Label dataset as sample below</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866601#M342239</link>
      <description>I would like to create a certain format Table.  N column is not the final variable, it actually a N+PCN, and format is like "N(%)"</description>
      <pubDate>Mon, 27 Mar 2023 18:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866601#M342239</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-27T18:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Label dataset as sample below</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866605#M342241</link>
      <description>&lt;P&gt;To combine datasets you first need same variable names which is not the case here. You can rename columns name from age to demo, sex to demo, and race to demo. But problem with this approach is they've formatted values. When you attempt to combine those datasets you will not get desired results due to different sas formats.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can explicitly create DEMO variable by passing values in your sas macro and then combine datasets. Here is the code that might help you. Though I haven't understood your requirement fully but you can play with this code to produce desired output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Macro A (Var);
data &amp;amp;Var.;
length N 8. Demo $50. ;
	set Tabulate_Output;
	if &amp;amp;Var. ^=.;
	Demo = put(&amp;amp;Var.,&amp;amp;Var..);
	keep N Demo;
run;
%mend;
%A (Age);
%A (Sex);
%A (Race);


data Want;
set Age Sex Race;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MayurJadhav_0-1679942882827.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82109i4BBE70035EEBFCC6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MayurJadhav_0-1679942882827.png" alt="MayurJadhav_0-1679942882827.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 18:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866605#M342241</guid>
      <dc:creator>MayurJadhav</dc:creator>
      <dc:date>2023-03-27T18:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Label dataset as sample below</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866606#M342242</link>
      <description>&lt;P&gt;Are you just asking how to use the PUT() function?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if not missing(sex) then demo=cats('Sex_',put(sex,sex.));
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Mar 2023 18:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866606#M342242</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-27T18:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Label dataset as sample below</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866608#M342244</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I would like to create a certain format Table. N column is not the final variable, it actually a N+PCN, and format is like "N(%)"&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't see how the original question moves you in that direction. Creating character strings that have the variable name &lt;EM&gt;and&amp;nbsp;&lt;/EM&gt;numeric values in the character string still seems like a poor idea (which makes me cringe) that doesn't get you anywhere. Data is easier to work with when text and numeric values and variable names are separate. And so again I urge you to not do this, and re-think the process. If you &lt;STRONG&gt;could explain the big picture&lt;/STRONG&gt; of what you are trying to do, &lt;STRONG&gt;rather than explain this particular step&lt;/STRONG&gt;, I'm sure some of us could help you re-design the process in a more effective way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please look at the &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Demographic-Table-and-Subgroup-Summary-Macro-TABLEN/ta-p/634030" target="_self"&gt;%TABLEN macro&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 19:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866608#M342244</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-27T19:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Label dataset as sample below</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866614#M342248</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&amp;nbsp;Here you can adjust PUT() function according to your VAR. to assign value to DEMO variable as per your requirement. I see in your Want datasets, there is a sequence attached after underscore(_), it can be attached using "_N_" var.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adjust %IF ELSE statements accordingly but here is the code just for your reference:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;		%if "&amp;amp;Var."="Age" %then %do;
				Demo=cat('Age_', put(&amp;amp;Var., &amp;amp;Var..), _N_); %end;
		%else %if "&amp;amp;Var."="Sex" %then %do;
				Demo=cat('Sex_', put(&amp;amp;Var., &amp;amp;Var..), _N_); %end;
		%else %if "&amp;amp;Var."="Race" %then %do;
				Demo=cat('Race_', put(&amp;amp;Var., &amp;amp;Var..), _N_); %end;&lt;/CODE&gt;&lt;/PRE&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>Mon, 27 Mar 2023 19:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866614#M342248</guid>
      <dc:creator>MayurJadhav</dc:creator>
      <dc:date>2023-03-27T19:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create a Label dataset as sample below</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866619#M342252</link>
      <description>Thanks for your valuable suggestion.  Unfortunately, I got "1-7" numbers at the end of your codes, while Tom's code is more clean to me.</description>
      <pubDate>Mon, 27 Mar 2023 19:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-Label-dataset-as-sample-below/m-p/866619#M342252</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-27T19:42:41Z</dc:date>
    </item>
  </channel>
</rss>

