<?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: Is there a workaround to set cards statement in macro? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285067#M59385</link>
    <description>&lt;P&gt;Actually I didn't thikn of that. That might be easier then if/then statements&lt;/P&gt;</description>
    <pubDate>Sat, 16 Jul 2016 23:02:23 GMT</pubDate>
    <dc:creator>Tpham</dc:creator>
    <dc:date>2016-07-16T23:02:23Z</dc:date>
    <item>
      <title>Is there a workaround to set cards statement in macro?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285053#M59381</link>
      <description>&lt;P&gt;So I am creating a macro to score a questionnaire. So the first part of the macro is calculating a raw score... and the second part is converting the raw score to a standardize score, where the standardize score would come from an existing table. I want this macro to be a stand alone program (called by my autoexec) so it can be moved from project to project.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand that I can't use Datalines/Cards within a macro. I am trying to figure out is there a workaround for this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is basically this is what I want, but the cards statement doesn't work in macros. I only thing I can think of is use the If/Then statement (so if rawscrore=1 then standarscore=14.5.. etc.). But I am wondering if there is an easier way to do this? Since it would be 200 lines (raw score can range from 1-200) if I were to use the if/then statement;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sample code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%Macro score;

*Some code to calculate the raw score variable;

Data have;
set fromscoringcodeabove (Keep=ID Rawscore);
run;

&lt;STRONG&gt;Data Standardscoretable;
input Rawscore standardscore;
cards;
1 14.5
2 17.9
3 20.5
4 24.4
;&lt;/STRONG&gt;

data want;
merge have (in=a) Standardscoretable;
if a;
by Rawscore;
run;&lt;BR /&gt;&lt;BR /&gt;%mend score;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jul 2016 18:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285053#M59381</guid>
      <dc:creator>Tpham</dc:creator>
      <dc:date>2016-07-16T18:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a workaround to set cards statement in macro?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285055#M59382</link>
      <description>&lt;P&gt;Use a format (defined with proc format) and the input function to convert raw to standardized scores.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jul 2016 19:40:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285055#M59382</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-07-16T19:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a workaround to set cards statement in macro?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285063#M59383</link>
      <description>&lt;P&gt;If you just want to make such a simple dataset then there is no need for CARDS/DATALINES.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data standardscoretable;
  do standardscore=14.5,17.9,20.5,24.4;
    rawscore+1;
    output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Jul 2016 22:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285063#M59383</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-16T22:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a workaround to set cards statement in macro?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285065#M59384</link>
      <description>&lt;P&gt;the dataset is just an example. there are over 200 records &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jul 2016 22:58:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285065#M59384</guid>
      <dc:creator>Tpham</dc:creator>
      <dc:date>2016-07-16T22:58:59Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a workaround to set cards statement in macro?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285067#M59385</link>
      <description>&lt;P&gt;Actually I didn't thikn of that. That might be easier then if/then statements&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jul 2016 23:02:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285067#M59385</guid>
      <dc:creator>Tpham</dc:creator>
      <dc:date>2016-07-16T23:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a workaround to set cards statement in macro?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285068#M59386</link>
      <description>&lt;P&gt;There are several ways. One quick way is given. An Array is used to lookup - giving the Rawscore and to get the corresponding standardscore. This array can hold a maximum of 200 rawscores. In case it is more, you may replace it by the maximum value. Even a million can be held in the array if you want. I have used HAVE to mimic your rawscore data set. Here goes your Macro:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Rawscore;
datalines;
1 1
2 1
3 2
4 2
5 3
6 4
7 3
;
run;

Data Standardscoretable;
input Rawscore standardscore;
cards;
1 14.5
2 17.9
3 20.5
4 24.4
;
run;

%macro score;
data want;
format ID Rawscore newScore;
   if _N_ = 1 then do;
   array k[200] _temporary_;
      do until(eof);
         set Standardscoretable end = eof;
         k[Rawscore] = standardscore;
      end;
   end;
   set have;
   newScore = k[Rawscore];
drop standardscore;
run;
%mend;

%score;

proc print data = want;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Enjoy the Macro.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jul 2016 23:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285068#M59386</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-07-16T23:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a workaround to set cards statement in macro?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285070#M59387</link>
      <description>&lt;P&gt;200 records is nothing. Copy and paste them into your program file.&lt;/P&gt;
&lt;P&gt;If you don't want to put in the commas you can use a simple program to generate the list from an existing dataset with the commas between the values and just copy from that little file into your source code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename list temp;
data _null_;
  set mydataset ;
  file list;
  retain sep '=';
  put sep standardscore;
  sep = ',' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use a macro variable in your autocall macro. Then you can copy and paste from your source file and not worry about having to insert commas to make it look like code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let standardscores=14.5 17.9 20.5 24.4;

data standardscoretable;
 do rawscore=1 to countw(symget('standardscores'),' ');
   standardscore=input(scan(symget('standardscores'),rawscore,' '),32.);
   output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Jul 2016 00:05:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285070#M59387</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-07-17T00:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a workaround to set cards statement in macro?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285081#M59388</link>
      <description>You can make a text file to contain these CARDS data.</description>
      <pubDate>Sun, 17 Jul 2016 01:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285081#M59388</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-17T01:29:14Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a workaround to set cards statement in macro? (Here's My Kludge!)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285426#M59420</link>
      <description>&lt;P&gt;Here's&amp;nbsp;one of those should-I-be-proud-or-ashamed-of-this kludges. &amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro testio;

%let input=
1 14.5
2 17.9
3 20.5
4 24.4
;

filename io "%sysfunc(pathname(work))/workio.txt" lrecl=32767;

data _null_; file io; put "&amp;amp;input";

Data Standardscoretable; infile io; input Rawscore standardscore@@;

%mend;

%testio;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think many of us have at times become&amp;nbsp;obsessed with trying to get the equivalent of CARDS&amp;nbsp;(SAS),&amp;nbsp;SYSIN (MAINFRAME), or HERE DOCUMENTS (UNIX) to play nice with SAS macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my own&amp;nbsp;Coders' Coder stab at a&amp;nbsp;more general&amp;nbsp;solution&amp;nbsp;from 10+ years ago:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/034-30.pdf" target="_self"&gt;A Better SYSIN Than SYSIN: Instream Files on Any Platform&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I had hoped the new PROC STREAM might work inside&amp;nbsp;macros, but I couldn't figure out a way to&amp;nbsp;get it to work (please correct me if I messed up and&amp;nbsp;there's a way!).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stil, even if it doesn't work inside a macro, a quick glance&amp;nbsp;at some papers Google turned up by Don Henderson and Rick Langston suggests&amp;nbsp;there are some insanely great (or insanely insane!) things you can do with PROC STREAM, so I'll have to check it out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 03:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285426#M59420</guid>
      <dc:creator>tc</dc:creator>
      <dc:date>2016-07-19T03:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a workaround to set cards statement in macro? (Here's My Kludge!)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285532#M59427</link>
      <description>&lt;P&gt;If your'e on a platform w/PIPE support:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro testio;
Filename in pipe 'echo 1 14.5 2 17.9 3 20.5 4 24.4 ';
Data Standardscoretable; infile in; input Rawscore standardscore@@;
%mend;
%testio;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you go multi-line with the data, make sure each line has a trailing space!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 14:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Is-there-a-workaround-to-set-cards-statement-in-macro/m-p/285532#M59427</guid>
      <dc:creator>tc</dc:creator>
      <dc:date>2016-07-19T14:34:12Z</dc:date>
    </item>
  </channel>
</rss>

