<?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: Assigning SAS formats to a list of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114334#M259226</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tim,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The posted solutions are pointing in the right direction ... there's another issue I wanted to raise.&amp;nbsp; Does &amp;amp;VARLIST include all the variables in your data set, or just some.&amp;nbsp; At this point, the solutions generate formats for every variable in the data set.&amp;nbsp; If &amp;amp;VARLIST contains just a subset, you may want to start off with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc contents data=have (keep=&amp;amp;varlist) noprint out=_contents_ (keep=name);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Then you could use _contents_ instead of dictionary.columns in the proposed solutions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also note that you could save TYPE as well as NAME in the output data set.&amp;nbsp; That might be helpful if you want to add $ at the beginning of the format names for character variables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Jan 2013 21:32:37 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2013-01-03T21:32:37Z</dc:date>
    <item>
      <title>Assigning SAS formats to a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114330#M259222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I wonder if someone can offer a solution to my problem of assigning SAS formats to a list of variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I So, have a list of variables with a variety of SAS variable naming conventions (e.g., SEX, AGE_GROUP, var1-var100, a1A, a1B, etc.). I also have formats for each variable using the name of the variable plus an 'f' suffix as a naming convention (e.g., SEXf, AGE_GROUPf, var1f, a1Af, etc).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of writing a format statement that assigns the format for each variable (e.g., format var1 var1f.;) I wonder if it is possible to do this with a %array and a macro statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--Tim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 20:59:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114330#M259222</guid>
      <dc:creator>tallkell</dc:creator>
      <dc:date>2013-01-03T20:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning SAS formats to a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114331#M259223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Pull the list of variables from metadata.&amp;nbsp; Assume you have a dataset named WORK.HAVE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will work if all of your variables are numeric.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select catx(' ',name,catx(name,'F.'))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :varlist separated by ' '&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname = 'WORK'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and mename = 'HAVE'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now you can use &amp;amp;VARLIST in a FORMAT statement of another DATA or PROC step.&amp;nbsp; Or you could use PROC DATASETS to modify the data set and permanently attach the formats.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc print data=have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; format &amp;amp;varlist ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If some of your variables are character then you should really use "$nameF." for the format name, but SAS usually will automatically correct that type of error.&amp;nbsp; That is if you try to attach character format $SEXF. to a numeric variable SAS will automatically instead search for the numeric format SEXF.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114331#M259223</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-01-03T21:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning SAS formats to a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114332#M259224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;example(&lt;SPAN style="color: #ff0000;"&gt;red parts must in upcase&lt;/SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select catx(' ',name,cats(name,'f.')) into :names separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname='&lt;SPAN style="color: #ff0000;"&gt;SASHELP&lt;/SPAN&gt;' and memname='&lt;SPAN style="color: #ff0000;"&gt;CLASS&lt;/SPAN&gt;';&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;names;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114332#M259224</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2013-01-03T21:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning SAS formats to a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114333#M259225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This article may be useful :&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;A href="http://www2.sas.com/proceedings/sugi24/Coders/p096-24.pdf"&gt;A Fast Format Macro – How to Quickly Create a Format by Specifying the Endpoints&lt;/A&gt;&lt;BR /&gt;&lt;/STRONG&gt;Christine A. Smiley, Kestnbaum, a KnowledgeBase Marketing Company, Chicago, IL&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114333#M259225</guid>
      <dc:creator>MohammadFayaz</dc:creator>
      <dc:date>2013-01-03T21:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning SAS formats to a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114334#M259226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tim,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The posted solutions are pointing in the right direction ... there's another issue I wanted to raise.&amp;nbsp; Does &amp;amp;VARLIST include all the variables in your data set, or just some.&amp;nbsp; At this point, the solutions generate formats for every variable in the data set.&amp;nbsp; If &amp;amp;VARLIST contains just a subset, you may want to start off with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc contents data=have (keep=&amp;amp;varlist) noprint out=_contents_ (keep=name);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Then you could use _contents_ instead of dictionary.columns in the proposed solutions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also note that you could save TYPE as well as NAME in the output data set.&amp;nbsp; That might be helpful if you want to add $ at the beginning of the format names for character variables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 21:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114334#M259226</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-01-03T21:32:37Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning SAS formats to a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114335#M259227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Astounding,&lt;/P&gt;&lt;P&gt;For this problem, the &amp;amp;VARLIST would only include variables that require a format. Therefore, not all of the variables in my database would be included in the list. So, the _contents_ solution would be helpful.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--Tim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jan 2013 17:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114335#M259227</guid>
      <dc:creator>tallkell</dc:creator>
      <dc:date>2013-01-04T17:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning SAS formats to a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114336#M259228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the help Tom.&lt;/P&gt;&lt;P&gt;My database doesn't include CHARACTER fields, but it's helpful to know how to assign a character format using this approach.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--Tim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jan 2013 17:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114336#M259228</guid>
      <dc:creator>tallkell</dc:creator>
      <dc:date>2013-01-04T17:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning SAS formats to a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114337#M259229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you already have the list of variables then simple string manipulation will let you generate the required list of name/format pairs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let varlist=age sex;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; length varlist fmtlist $3000 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; varlist=symget('varlist');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; do i=1 to countw(varlist);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fmtlist=catx(' ',fmtlist,scan(varlist,i),scan(varlist,i)||'F.');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp; call symputx('fmtlist',fmtlist);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;....&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;format &amp;amp;fmtlist ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jan 2013 18:16:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-SAS-formats-to-a-list-of-variables/m-p/114337#M259229</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-01-04T18:16:46Z</dc:date>
    </item>
  </channel>
</rss>

