<?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: SAS: create a string to use as a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579194#M164386</link>
    <description>&lt;P&gt;So you have a badly structured dataset to begin with. Data (sale items or similar) stored as column names.&lt;/P&gt;
&lt;P&gt;Start with transposing to a long format, and what you want to analyze becomes dead simple.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129748"&gt;@Pooja2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Tom for your response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is giving me "2412","erer","ghgh" for nonmissing values but if I have any missing value it is giving me "2431"," "," " if I have missing values. If I have missing values then I just want "2431". so that my data pull does not give me any blank cells when I use this in my where clause.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;I have a dataset where I have different customers cust 1, cust 2, ...custn in each rows and then their corresponding ids as id1, id2, id3. Sometimes more than 1 id is missing but at least one id will be populated. I have 150 rows. I have to create a summary for each customer (if there id in id1,id2, and id3) for example - how many shirts they have bought. so if I have a variable for id then I can use that in a where clause as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; ; &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; COUNT(*) &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;INTO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; :NUMROWS &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;FROM&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;want&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;QUIT&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;DELETE&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; DATA=TOGETHER;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%MACRO SHIRT;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%DO I=1 %TO &amp;amp;NUMROWS;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;DATA CHECK;SET WANT; IF _N_=&amp;amp;I;RUN;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PROC SQL;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SELECT CUST AS CUST,&amp;nbsp;ID AS&amp;nbsp;ID INTO :CUST, :ID FROM CHECK;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;QUIT;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PROC SQL;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;CREATE TABLE CLMS AS&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SELECT *&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;FROM&amp;nbsp;OTHERDATA&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;WHERE&amp;nbsp;A.ID IN (&lt;/SPAN&gt;&lt;SPAN style="color: purple; font-family: 'Courier New'; font-size: 10pt;"&gt;"&amp;amp;ID."&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;AND A.CUSTOMER IN (&lt;/SPAN&gt;&lt;SPAN style="color: purple; font-family: 'Courier New'; font-size: 10pt;"&gt;"&amp;amp;CUST."&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;QUIT;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Aug 2019 17:43:14 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2019-08-05T17:43:14Z</dc:date>
    <item>
      <title>SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579150#M164367</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; datalines &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;missover&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; IDnumber1 $ IDnumber2 $ IDnumber3 $; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2477 sdsd dfdf&lt;/P&gt;&lt;P&gt;2431&lt;/P&gt;&lt;P&gt;2456 dfdf ghgh&lt;/P&gt;&lt;P&gt;2412 erer ghgh&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a variable for each obs like this&lt;/P&gt;&lt;P&gt;newvar for row 1: '2477','sdsd', 'dfdf'&lt;/P&gt;&lt;P&gt;newvar for row 2: '2431'&lt;/P&gt;&lt;P&gt;newvar for row 3: '2456','dfdf','ghgh'&lt;/P&gt;&lt;P&gt;newvar for row 4: '2412','erer','ghgh'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create this to use them as a macro in a where clause.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Pooja&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 15:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579150#M164367</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2019-08-05T15:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579155#M164370</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129748"&gt;@Pooja2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; datalines &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;missover&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; IDnumber1 $ IDnumber2 $ IDnumber3 $; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2477 sdsd dfdf&lt;/P&gt;
&lt;P&gt;2431&lt;/P&gt;
&lt;P&gt;2456 dfdf ghgh&lt;/P&gt;
&lt;P&gt;2412 erer ghgh&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a variable for each obs like this&lt;/P&gt;
&lt;P&gt;newvar for row 1: '2477','sdsd', 'dfdf'&lt;/P&gt;
&lt;P&gt;newvar for row 2: '2431'&lt;/P&gt;
&lt;P&gt;newvar for row 3: '2456','dfdf','ghgh'&lt;/P&gt;
&lt;P&gt;newvar for row 4: '2412','erer','ghgh'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create this to use them as a macro in a where clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you mean you want to use them as a MACRO VARIABLE? (This is not the same as using them as a MACRO)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
infile datalines missover;
input IDnumber1 $ IDnumber2 $ IDnumber3 $;
call symputx('mvar'||left(_n_),catx(',',quote(trim(idnumber1)),
    quote(trim(idnumber2)),quote(trim(idnumber3))));
datalines;
2477 sdsd dfdf
2431
2456 dfdf ghgh
2412 erer ghgh
;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This creates macro variables &amp;amp;MVAR1 &amp;amp;MVAR2 &amp;amp;MVAR3 and &amp;amp;MVAR4, one from each row of the input data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 15:16:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579155#M164370</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-05T15:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579156#M164371</link>
      <description>&lt;P&gt;You can use QUOTE() to add quotes.&amp;nbsp; And CATX() to add the commas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have ;
   length string $200;
   string=catx(',',quote(trim(idnumber1)),quote(trim(idnumber2)),quote(trim(idnumber3)));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you need single quotes or are double quotes good enough?&amp;nbsp; For example you might be using the value to generate code that is passed into a remote database that requires single quotes.&amp;nbsp; Or the values might contain &amp;amp; or % characters that would trigger the macro processor if using inside of double quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;quote(trim(idnumber1),"'")&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Aug 2019 15:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579156#M164371</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-05T15:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579161#M164373</link>
      <description>&lt;P&gt;A considerable percent of the time when someone attempts to stuff an entire dataset into macro variables it indicates that they are about to abuse the macro system or are about to attempt something that probably does not belong in macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, how exactly are you using those macro variables after they are created? If ALL of those are going into a single Where clause then almost certainly macro variables are not needed.&lt;/P&gt;
&lt;P&gt;If you already have values in a data set often some form of join is appropriate to select records.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 15:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579161#M164373</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-05T15:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579162#M164374</link>
      <description>&lt;P&gt;alternative way with proc sql to create the macro variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines missover;
input IDnumber1 $ IDnumber2 $ IDnumber3 $;
newvar=cats(quote(compress(IDnumber1)),',',quote(compress(IDnumber2)),',',quote(compress(IDnumber3)));
datalines;
2477 sdsd dfdf
2431
2456 dfdf ghgh
2412 erer ghgh
;
run;

proc sql;
select newvar into :mvar1 - : mvar&amp;amp;sysmaxlong from have;
quit;

%put &amp;amp;mvar1 &amp;amp;mvar2  &amp;amp;mvar3  &amp;amp;mvar4;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Aug 2019 15:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579162#M164374</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-05T15:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579163#M164375</link>
      <description>Just want to underline what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; already said: storing data in macro variables is almost always a bad idea or a lack of knowledge.</description>
      <pubDate>Mon, 05 Aug 2019 15:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579163#M164375</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-08-05T15:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579192#M164384</link>
      <description>&lt;P&gt;Thanks Tom for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it is giving me "2412","erer","ghgh" for nonmissing values but if I have any missing value it is giving me "2431"," "," " if I have missing values. If I have missing values then I just want "2431". so that my data pull does not give me any blank cells when I use this in my where clause.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;I have a dataset where I have different customers cust 1, cust 2, ...custn in each rows and then their corresponding ids as id1, id2, id3. Sometimes more than 1 id is missing but at least one id will be populated. I have 150 rows. I have to create a summary for each customer (if there id in id1,id2, and id3) for example - how many shirts they have bought. so if I have a variable for id then I can use that in a where clause as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; ; &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; COUNT(*) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;INTO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; :NUMROWS &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;FROM&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;want&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;QUIT&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;DELETE&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; DATA=TOGETHER;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%MACRO SHIRT;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%DO I=1 %TO &amp;amp;NUMROWS;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DATA CHECK;SET WANT; IF _N_=&amp;amp;I;RUN;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PROC SQL;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;SELECT CUST AS CUST,&amp;nbsp;ID AS&amp;nbsp;ID INTO :CUST, :ID FROM CHECK;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;QUIT;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;PROC SQL;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;CREATE TABLE CLMS AS&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;SELECT *&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;FROM&amp;nbsp;OTHERDATA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;WHERE&amp;nbsp;A.ID IN (&lt;/SPAN&gt;&lt;SPAN style="color: purple; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;"&amp;amp;ID."&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;AND A.CUSTOMER IN (&lt;/SPAN&gt;&lt;SPAN style="color: purple; font-family: &amp;quot;Courier New&amp;quot;; font-size: 10pt;"&gt;"&amp;amp;CUST."&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;QUIT;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 17:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579192#M164384</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2019-08-05T17:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579193#M164385</link>
      <description>&lt;P&gt;Thanks Ballardw. I am still learning and I am aware I need to improve. I explained my problem in detail in the post. I hope you can give me your suggestion based on my problem.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 17:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579193#M164385</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2019-08-05T17:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579194#M164386</link>
      <description>&lt;P&gt;So you have a badly structured dataset to begin with. Data (sale items or similar) stored as column names.&lt;/P&gt;
&lt;P&gt;Start with transposing to a long format, and what you want to analyze becomes dead simple.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129748"&gt;@Pooja2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Tom for your response.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it is giving me "2412","erer","ghgh" for nonmissing values but if I have any missing value it is giving me "2431"," "," " if I have missing values. If I have missing values then I just want "2431". so that my data pull does not give me any blank cells when I use this in my where clause.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;I have a dataset where I have different customers cust 1, cust 2, ...custn in each rows and then their corresponding ids as id1, id2, id3. Sometimes more than 1 id is missing but at least one id will be populated. I have 150 rows. I have to create a summary for each customer (if there id in id1,id2, and id3) for example - how many shirts they have bought. so if I have a variable for id then I can use that in a where clause as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; ; &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; COUNT(*) &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;INTO&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; :NUMROWS &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;FROM&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;want&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;QUIT&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;DELETE&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; DATA=TOGETHER;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%MACRO SHIRT;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%DO I=1 %TO &amp;amp;NUMROWS;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;DATA CHECK;SET WANT; IF _N_=&amp;amp;I;RUN;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PROC SQL;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SELECT CUST AS CUST,&amp;nbsp;ID AS&amp;nbsp;ID INTO :CUST, :ID FROM CHECK;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;QUIT;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PROC SQL;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;CREATE TABLE CLMS AS&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SELECT *&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;FROM&amp;nbsp;OTHERDATA&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;WHERE&amp;nbsp;A.ID IN (&lt;/SPAN&gt;&lt;SPAN style="color: purple; font-family: 'Courier New'; font-size: 10pt;"&gt;"&amp;amp;ID."&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;AND A.CUSTOMER IN (&lt;/SPAN&gt;&lt;SPAN style="color: purple; font-family: 'Courier New'; font-size: 10pt;"&gt;"&amp;amp;CUST."&lt;/SPAN&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;QUIT;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Calibri" size="3" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 17:43:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579194#M164386</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-05T17:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579195#M164387</link>
      <description>&lt;P&gt;I have unique cust in each row. It is a clean data.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 17:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579195#M164387</guid>
      <dc:creator>Pooja2</dc:creator>
      <dc:date>2019-08-05T17:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579197#M164388</link>
      <description>&lt;P&gt;It shouldn't matter if the list includes the blanks (or duplicate values either) if you are just using it in a WHERE clause.&lt;/P&gt;
&lt;P&gt;If you want to ignore blank values (why would you have blank values in the column being queried?) you can add another criteria.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list="2431"," "," " ;
....
  where item in (&amp;amp;list) 
    and not missing(item)
....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Aug 2019 17:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579197#M164388</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-05T17:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579213#M164394</link>
      <description>&lt;P&gt;Notice how many times you are hitting your claims data.&amp;nbsp; If you have 1,000 claims to look up, your plan is to hit the claims data 1,000 times.&amp;nbsp; Surely there must be another way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the approach I would try.&amp;nbsp; The syntax is not checked, as you have the data, but the approach should extract all the claims of interest with just one pass through the data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as select * from otherdata
where catx(cust, ',' , id) in select (catx(cust, ',' , id) from check) ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Aug 2019 19:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579213#M164394</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-08-05T19:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579218#M164395</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129748"&gt;@Pooja2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Ballardw. I am still learning and I am aware I need to improve. I explained my problem in detail in the post. I hope you can give me your suggestion based on my problem.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Provide examples of both input data sets and the desired result(s) is usually a best practice for any question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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"&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&lt;STRONG&gt; a forum code box using the {i} icon&lt;/STRONG&gt; or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2019 19:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579218#M164395</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-05T19:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS: create a string to use as a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579277#M164419</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129748"&gt;@Pooja2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have unique cust in each row. It is a clean data.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Every time I see something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input IDnumber1 $ IDnumber2 $ IDnumber3 $;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the back of my head screams "Design problem! Un-transpose!". And that's what will happen in 99% of the time.&lt;/P&gt;
&lt;P&gt;So either you have a table design problem, or you did not give us a useful example of your dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what will you be doing with the resulting macro variable, anyway? See Maxim 43. Because this will determine the (best) method to use, and I have a strong inkling that it won't be a large macro variable.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 05:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-create-a-string-to-use-as-a-macro/m-p/579277#M164419</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-08-06T05:42:54Z</dc:date>
    </item>
  </channel>
</rss>

