<?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 What is this piece of code doing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836618#M330792</link>
    <description>&lt;P&gt;Hello programmers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please can someone summarize what this code is doing? I'm new to SAS macro but this code has been confusing a little bit. I understand that it's doing an array over 16 items&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro jorm (base, better, worse, first, y, raw);

data jorm_&amp;amp;y; set raw.&amp;amp;raw (keep = hhid pn &amp;amp;base &amp;amp;better &amp;amp;worse); 
	array base [16] &amp;amp;base;
	array better [16] &amp;amp;better;
	array worse [16] &amp;amp;worse;
	array jorm [16] jorm_&amp;amp;y._1 - jorm_&amp;amp;y._16;

	if &amp;amp;first NE . then do;

		iqcode_dkrf_&amp;amp;y = 0; 

		do i = 1 to 16;
			
			if base[i] = 1 then do; /*better*/
				if better[i] = 1 then jorm[i] = 1; /*much better*/
				else if better[i] in (2, 8, 9) then jorm[i] = 2; /*a bit better*/
			end;

			else if base[i] = 2 then jorm[i] = 3; /*same*/

			else if base[i] = 3 then do; /*worse*/
				if worse[i] in (4, 8, 9) then jorm[i] = 4; /*a bit worse*/
				else if worse[i] = 5 then jorm[i] = 5; /*much worse*/
			end;

			else if base[i] in (8, 9) then do; /*8=dk/na, 9=rf*/
				jorm[i] = .;
				iqcode_dkrf_&amp;amp;y = iqcode_dkrf_&amp;amp;y + 1; /*count of dk/na*/
			end;

			else if base[i] = 4 then do; /*4=NotApplicable - do NOT count as dk/rf*/
				jorm[i] = .;
			end;

		end;
		
		IQCODE_&amp;amp;y = mean (of jorm[*]); /*mean IQCODE score over non-missing items*/

		if iqcode_dkrf_&amp;amp;y &amp;gt; 3 then IQCODE_&amp;amp;y = .;	/* set to missing 4+ dk/rf*/

	end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;. Please I'll appreciate straight contributions, any referral will not help at this point.&amp;nbsp; Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Oct 2022 00:38:21 GMT</pubDate>
    <dc:creator>ChuksManuel</dc:creator>
    <dc:date>2022-10-04T00:38:21Z</dc:date>
    <item>
      <title>What is this piece of code doing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836618#M330792</link>
      <description>&lt;P&gt;Hello programmers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please can someone summarize what this code is doing? I'm new to SAS macro but this code has been confusing a little bit. I understand that it's doing an array over 16 items&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro jorm (base, better, worse, first, y, raw);

data jorm_&amp;amp;y; set raw.&amp;amp;raw (keep = hhid pn &amp;amp;base &amp;amp;better &amp;amp;worse); 
	array base [16] &amp;amp;base;
	array better [16] &amp;amp;better;
	array worse [16] &amp;amp;worse;
	array jorm [16] jorm_&amp;amp;y._1 - jorm_&amp;amp;y._16;

	if &amp;amp;first NE . then do;

		iqcode_dkrf_&amp;amp;y = 0; 

		do i = 1 to 16;
			
			if base[i] = 1 then do; /*better*/
				if better[i] = 1 then jorm[i] = 1; /*much better*/
				else if better[i] in (2, 8, 9) then jorm[i] = 2; /*a bit better*/
			end;

			else if base[i] = 2 then jorm[i] = 3; /*same*/

			else if base[i] = 3 then do; /*worse*/
				if worse[i] in (4, 8, 9) then jorm[i] = 4; /*a bit worse*/
				else if worse[i] = 5 then jorm[i] = 5; /*much worse*/
			end;

			else if base[i] in (8, 9) then do; /*8=dk/na, 9=rf*/
				jorm[i] = .;
				iqcode_dkrf_&amp;amp;y = iqcode_dkrf_&amp;amp;y + 1; /*count of dk/na*/
			end;

			else if base[i] = 4 then do; /*4=NotApplicable - do NOT count as dk/rf*/
				jorm[i] = .;
			end;

		end;
		
		IQCODE_&amp;amp;y = mean (of jorm[*]); /*mean IQCODE score over non-missing items*/

		if iqcode_dkrf_&amp;amp;y &amp;gt; 3 then IQCODE_&amp;amp;y = .;	/* set to missing 4+ dk/rf*/

	end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;. Please I'll appreciate straight contributions, any referral will not help at this point.&amp;nbsp; Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 00:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836618#M330792</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2022-10-04T00:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: What is this piece of code doing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836620#M330793</link>
      <description>&lt;P&gt;What's between %macro jnorm.... and %mend ... is your macro definition. You then call this macro somewhere in code like %jnorm(&amp;lt;and here the parameter passing&amp;gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;base, better etc. are the parameter names.&lt;/P&gt;
&lt;P&gt;For example in your macro definition you've got&lt;/P&gt;
&lt;P&gt;- %macro jnorm (base,...&lt;/P&gt;
&lt;P&gt;- In the code you've got&amp;nbsp;array base [16] &amp;amp;base;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you call the macro you pass a value like:&amp;nbsp;%jnorm(myVar1, ...&lt;/P&gt;
&lt;P&gt;The macro then executes and replaces all macro variables with the parameter value you've passed.&lt;BR /&gt;-&amp;nbsp;array base [16] myVar1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First the SAS macro language resolves and then "normal" SAS executes the code that has been generated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a working call to the macro then you can capture the generated SAS code using the MFILE option. After that it's just about understanding "normal" SAS code.&lt;BR /&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0j3zpinabl49ln13q5f5r1t46mg.htm" target="_blank" rel="noopener"&gt;https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0j3zpinabl49ln13q5f5r1t46mg.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;filename mprint '&amp;lt;path of your choosing&amp;gt;/jnorm_gen.sas';
options MPRINT MFILE;
%jnorm(...and here comma separated list of parameter values);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 01:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836620#M330793</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-10-04T01:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: What is this piece of code doing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836623#M330794</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Oct 2022 01:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836623#M330794</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2022-10-04T01:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: What is this piece of code doing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836988#M330951</link>
      <description>&lt;P&gt;Do you by chance know what this code is doing?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;if &amp;amp;first NE . then do;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the macro&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro jorm (base, better, worse, first, y, raw);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I know base, better and worse are in the do loop, and are used to create Jorm scores.&lt;BR /&gt;y is the wave year (1990-2018)&lt;BR /&gt;raw is the raw dataset.&lt;BR /&gt;What is the "first" in the macro doing?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 15:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836988#M330951</guid>
      <dc:creator>ChuksManuel</dc:creator>
      <dc:date>2022-10-05T15:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: What is this piece of code doing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836989#M330952</link>
      <description>&lt;P&gt;&amp;amp;first is&amp;nbsp; a variable most likley.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It does matter how it's defined in the macro call though, so &amp;amp;first is coming from the call which would translate to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if someVariable is not missing then do.....&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2022 15:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-this-piece-of-code-doing/m-p/836989#M330952</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-05T15:47:16Z</dc:date>
    </item>
  </channel>
</rss>

