<?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 Append values and keep leading zeros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732211#M228164</link>
    <description>&lt;P&gt;In the program below, leading zeros are getting truncated but I want to keep leading zeros in the ID variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let id=0012,0333;
%let id=%sysfunc(catq(1ac,&amp;amp;id));
%put #####&amp;amp;id.; 
&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;26         %let id=0012,0333;
27         %let id=%sysfunc(catq(1ac,&amp;amp;id));
28         %put #####&amp;amp;id.;
#####'12','333'&lt;/PRE&gt;
&lt;P&gt;Desired Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Id should resolve to &lt;STRONG&gt;'0012','0333'&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help?&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Apr 2021 13:08:29 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2021-04-08T13:08:29Z</dc:date>
    <item>
      <title>Append values and keep leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732211#M228164</link>
      <description>&lt;P&gt;In the program below, leading zeros are getting truncated but I want to keep leading zeros in the ID variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let id=0012,0333;
%let id=%sysfunc(catq(1ac,&amp;amp;id));
%put #####&amp;amp;id.; 
&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;26         %let id=0012,0333;
27         %let id=%sysfunc(catq(1ac,&amp;amp;id));
28         %put #####&amp;amp;id.;
#####'12','333'&lt;/PRE&gt;
&lt;P&gt;Desired Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Id should resolve to &lt;STRONG&gt;'0012','0333'&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help?&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 13:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732211#M228164</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-04-08T13:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: Append values and keep leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732216#M228166</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let id=%sysfunc(catq(1ac,%bquote(&amp;amp;id)));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Apr 2021 13:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732216#M228166</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-08T13:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: Append values and keep leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732217#M228167</link>
      <description>&lt;P&gt;Use the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=p0frhtfqvguv78n1owh5wfeopdrj.htm&amp;amp;locale=en" target="_self"&gt;%Bquote&lt;/A&gt;&amp;nbsp;Function on the macro variable.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 13:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732217#M228167</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-04-08T13:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Append values and keep leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732218#M228168</link>
      <description>&lt;P&gt;It is because you are trying to use a data step function on your macro variable values.&amp;nbsp; In particular one that can take either numeric or character values for its arguments.&lt;/P&gt;
&lt;P&gt;But why would you ever call any CATxxx function in macro code? To concatenate macro variable values just expand them next to each other.&lt;/P&gt;
&lt;P&gt;To do this transformation just change the commas to quoted commas and add quotes on the outside.&amp;nbsp; Easier with double quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let id=0012,0333;
%put %sysfunc(tranwrd("&amp;amp;id",%str(,),","));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need single quotes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let id=0012,0333;
%put %sysfunc(tranwrd(%bquote('&amp;amp;id'),%str(,),','));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 13:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732218#M228168</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-08T13:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Append values and keep leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732219#M228169</link>
      <description>&lt;P&gt;Is there a reason that you have to define them with a LET statement? If you have them in a data set, it's probably easier to do this, and it gives you the output you need. More of a data-driven technique.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $;
datalines;
0012
0333
;
run;

proc sql noprint;
	select
				quote(trim(id))
					into: ids separated by ","
	from
				have;
quit;

%put ####&amp;amp;ids.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt; %put ####&amp;amp;ids.;
####"0012","0333"
&lt;/PRE&gt;
&lt;P&gt;I'm not terribly experienced with manipulating data with macro quoting functions, so someone else may have better insight than my solution.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 13:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Append-values-and-keep-leading-zeros/m-p/732219#M228169</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-04-08T13:27:42Z</dc:date>
    </item>
  </channel>
</rss>

