<?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: Creating Macro for Value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883933#M349207</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76823"&gt;@ambadi007&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;need to check the Pvalue for first visit(Baseline) and all other visits&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi, I find this to be unclear as well, and request a detailed explanation. Be generous with information!&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jul 2023 11:05:21 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-07-07T11:05:21Z</dc:date>
    <item>
      <title>Creating Macro for Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883913#M349196</link>
      <description>&lt;P&gt;HI Team,&lt;/P&gt;&lt;P&gt;I have a requirement to create Pvalue based on distribution of data , below is the requirement.&lt;/P&gt;&lt;P&gt;1 If data follows normal distribution, &lt;STRONG&gt;P-values&lt;/STRONG&gt; were derived using paired sample t-test else by Wilcoxon test for baseline vs all the timepoints.&lt;/P&gt;&lt;P&gt;The below codes i have written , but the codes are too lengthy. Could you please help to make it in a macro&lt;/P&gt;&lt;PRE&gt;/*Method 1 - Paired T test*/

%macro pir(dat1=,visn=,parn=,out=,rm=);

data &amp;amp;dat1;
set input;
where parcat1n=&amp;amp;parn. and  avisn=&amp;amp;visn.;
run;

ods trace on;
ods output TTests=&amp;amp;out. ;
proc ttest data=&amp;amp;dat1. alpha=0.05;
paired base*aval;
run; 
ods trace off;

data &amp;amp;out._1(rename=(probc=&amp;amp;rm.));
set &amp;amp;out.;
probc=put(Probt,pvalue6.4)||"^{Super 1}";
label=" P-value";
ord=8.1;
keep label ord Variable1 Variable2 Difference probc;
run;

%mend;
%pir(dat1=input1,visn=1,parn=1,out=l_wk1,rm=_Lesional_);
%pir(dat1=input1,visn=1,parn=2,out=nl_wk1,rm=_Non_Lesional_);
%pir(dat1=input1,visn=1,parn=3,out=h_wk1,rm=_Healthy_);

%pir(dat1=input1,visn=2,parn=1,out=l_wk2,rm=_Lesional_);
%pir(dat1=input1,visn=2,parn=2,out=nl_wk2,rm=_Non_Lesional_);
%pir(dat1=input1,visn=2,parn=3,out=h_wk2,rm=_Healthy_);

%pir(dat1=input1,visn=3,parn=1,out=l_wk3,rm=_Lesional_);
%pir(dat1=input1,visn=3,parn=2,out=nl_wk3,rm=_Non_Lesional_);
%pir(dat1=input1,visn=3,parn=3,out=h_wk3,rm=_Healthy_);

%pir(dat1=input1,visn=4,parn=1,out=l_wk4,rm=_Lesional_);
%pir(dat1=input1,visn=4,parn=2,out=nl_wk4,rm=_Non_Lesional_);
%pir(dat1=input1,visn=4,parn=3,out=h_wk4,rm=_Healthy_);

%pir(dat1=input1,visn=5,parn=1,out=l_wk6,rm=_Lesional_);
%pir(dat1=input1,visn=5,parn=2,out=nl_wk6,rm=_Non_Lesional_);
%pir(dat1=input1,visn=5,parn=3,out=h_wk6,rm=_Healthy_);

%pir(dat1=input1,visn=6,parn=1,out=l_wk8,rm=_Lesional_);
%pir(dat1=input1,visn=6,parn=2,out=nl_wk8,rm=_Non_Lesional_);
%pir(dat1=input1,visn=6,parn=3,out=h_wk8,rm=_Healthy_);

%pir(dat1=input1,visn=7,parn=1,out=l_wk12,rm=_Lesional_);
%pir(dat1=input1,visn=7,parn=2,out=nl_wk12,rm=_Non_Lesional_);
%pir(dat1=input1,visn=7,parn=3,out=h_wk12,rm=_Healthy_);

%pir(dat1=input1,visn=8,parn=1,out=l_wk16,rm=_Lesional_);
%pir(dat1=input1,visn=8,parn=2,out=nl_wk16,rm=_Non_Lesional_);
%pir(dat1=input1,visn=8,parn=3,out=h_wk16,rm=_Healthy_);

%pir(dat1=input1,visn=9,parn=1,out=l_wk28,rm=_Lesional_);
%pir(dat1=input1,visn=9,parn=2,out=nl_wk28,rm=_Non_Lesional_);
%pir(dat1=input1,visn=9,parn=3,out=h_wk28,rm=_Healthy_);


%macro mrg(in_1=,in_2=,in_3=,vsn=,out=);
data &amp;amp;out.;
merge &amp;amp;in_1. &amp;amp;in_2. &amp;amp;in_3.;
by Variable1 Variable2;
avisn=&amp;amp;vsn.;
run;
%mend;

 %mrg(in_1=l_wk1_1,in_2=nl_wk1_1,in_3=h_wk1_1,vsn=1,out=p_wk1);
 %mrg(in_1=l_wk2_1,in_2=nl_wk2_1,in_3=h_wk2_1,vsn=2,out=p_wk2);
 %mrg(in_1=l_wk3_1,in_2=nl_wk3_1,in_3=h_wk3_1,vsn=3,out=p_wk3);
 %mrg(in_1=l_wk4_1,in_2=nl_wk4_1,in_3=h_wk4_1,vsn=4,out=p_wk4);
 %mrg(in_1=l_wk6_1,in_2=nl_wk6_1,in_3=h_wk6_1,vsn=5,out=p_wk6);
 %mrg(in_1=l_wk8_1,in_2=nl_wk8_1,in_3=h_wk8_1,vsn=6,out=p_wk8);
 %mrg(in_1=l_wk12_1,in_2=nl_wk12_1,in_3=h_wk12_1,vsn=7,out=p_wk12);
 %mrg(in_1=l_wk16_1,in_2=nl_wk16_1,in_3=h_wk16_1,vsn=8,out=p_wk16);
 %mrg(in_1=l_wk28_1,in_2=nl_wk28_1,in_3=h_wk28_1,vsn=9,out=p_wk28);

 /*Paired Ttest values*/

data PT_pval(rename=(variable2=varname));
set p_wk1 p_wk2 p_wk3 p_wk4 p_wk6 p_wk8 p_wk12 p_wk16 p_wk28;
run;

/*Checking normality of the dristribution to understand which test needs to perform*/
 
%macro uni(var=,a=,b=,d=,rnm=);

data input_1;
set input;
where  parcat1n=&amp;amp;b. ;
run;

proc sort;by avisn;run;

ods trace on;
ods output TestsForNormality=&amp;amp;d.;
Proc univariate data=input_1 normal;
var &amp;amp;var.;
by avisn;
RUN;
ods trace off;

data &amp;amp;d.(rename=(pValue=&amp;amp;rnm.));
set &amp;amp;d.;
where TEST="Shapiro-Wilk";
run;

%mend;

%uni(var=chg,b=1,d=pv_l_0s,rnm=ls);

%uni(var=chg,b=2,d=pv_nl_0s,rnm=nls);

%uni(var=chg,b=3,d=pv_h_0s,rnm=hs);


%macro mr(a=,in=,ord=);
data &amp;amp;a.;
merge &amp;amp;in.;
by avisn;
sord=&amp;amp;ord.;
keep avisn  VarName Test ls nls hs sord;
run;
%mend;
%mr(a=pval_0s,in=pv_l_0s pv_nl_0s pv_h_0s,ord=0);


data pvalue_T415;
	Length nvar $9.;
	set pval_0s;
	if ls&amp;lt;0.05 then nvar="ls";
	if nls&amp;lt;0.05 then nvar="nls";
	if hs&amp;lt;0.05 then nvar="hs";
	if ls&amp;lt;0.05 and hs&amp;lt;0.05 then nvar="lshs";
	if ls&amp;lt;0.05 and nls&amp;lt;0.05 then nvar="lsnls";
	if nls&amp;lt;0.05 and hs&amp;lt;0.05 then nvar="nlshs";
	if ls&amp;lt;0.05 and nls&amp;lt;0.05 and hs&amp;lt;0.05 then nvar="lsnlshs";
	if ls ne . and nls ne . and hs ne .;
run;

/*Method 2 Non parametric method*/

%macro par(a=,b=,c=,rnm=);
data input1;
set input;
where parcat1n=&amp;amp;a.  and avisn in &amp;amp;b.;
run;;

proc sort data=input1;
by parcat1;
run;

ods trace on;
ods output TestsForLocation=&amp;amp;c.;
Proc univariate data=input1;
Var chg;
Run;
ods trace off;

data &amp;amp;c.(rename=(pValue=&amp;amp;rnm.));
Length varname $4.;
set &amp;amp;c.;
where Test="Signed Rank";
varname="AVAL";
run;

%mend;
%par(a=1,b=(0,1),c=ls_1,rnm=npls);
%par(a=2,b=(0,1),c=nls_1,rnm=npnls);
%par(a=3,b=(0,1),c=hs_1,rnm=nphs);

%par(a=1,b=(0,2),c=ls_2,rnm=npls);
%par(a=2,b=(0,2),c=nls_2,rnm=npnls);
%par(a=3,b=(0,2),c=hs_2,rnm=nphs);

%par(a=1,b=(0,3),c=ls_3,rnm=npls);
%par(a=2,b=(0,3),c=nls_3,rnm=npnls);
%par(a=3,b=(0,3),c=hs_3,rnm=nphs);

%par(a=1,b=(0,4),c=ls_4,rnm=npls);
%par(a=2,b=(0,4),c=nls_4,rnm=npnls);
%par(a=3,b=(0,4),c=hs_4,rnm=nphs);

%par(a=1,b=(0,5),c=ls_5,rnm=npls);
%par(a=2,b=(0,5),c=nls_5,rnm=npnls);
%par(a=3,b=(0,5),c=hs_5,rnm=nphs);

%par(a=1,b=(0,6),c=ls_6,rnm=npls);
%par(a=2,b=(0,6),c=nls_6,rnm=npnls);
%par(a=3,b=(0,6),c=hs_6,rnm=nphs);

%par(a=1,b=(0,7),c=ls_7,rnm=npls);
%par(a=2,b=(0,7),c=nls_7,rnm=npnls);
%par(a=3,b=(0,7),c=hs_7,rnm=nphs);


%par(a=1,b=(0,8),c=ls_8,rnm=npls);
%par(a=2,b=(0,8),c=nls_8,rnm=npnls);
%par(a=3,b=(0,8),c=hs_8,rnm=nphs);

%par(a=1,b=(0,9),c=ls_9,rnm=npls);
%par(a=2,b=(0,9),c=nls_9,rnm=npnls);
%par(a=3,b=(0,9),c=hs_9,rnm=nphs);

%macro mr(a=,in=,ord=);
data &amp;amp;a.;
merge &amp;amp;in.;
by varname;
sord=&amp;amp;ord.;
keep varname test npls npnls nphs sord;
run;
%mend;

%mr(a=np_1,in=ls_1 nls_1 hs_1,ord=1);

%mr(a=np_2,in=ls_2 nls_2 hs_2,ord=2);

%mr(a=np_3,in=ls_3 nls_3 hs_3,ord=3);

%mr(a=np_4,in=ls_4 nls_4 hs_4,ord=4);

%mr(a=np_5,in=ls_5 nls_5 hs_5,ord=5);

%mr(a=np_6,in=ls_6 nls_6 hs_6,ord=6);

%mr(a=np_7,in=ls_7 nls_7 hs_7,ord=7);

%mr(a=np_8,in=ls_8 nls_8 hs_8,ord=8);

%mr(a=np_9,in=ls_9 nls_9 hs_9,ord=9);


data np_T415(rename=(ls=npls nls=npnls hs=nphs sord=avisn));
Length varname $4.;
set np_1-np_9;
ls=put(npls,pvalue6.4)||"^{Super 2}";
nls=put(npnls,pvalue6.4)||"^{Super 2}";
hs=put(nphs,pvalue6.4)||"^{Super 2}";
drop npls npnls nphs;
run;

proc sort data=np_T415;by avisn;run;

proc sort data=pvalue_T415;by avisn;run;

data final_T415;
	Length varname $4.;
	merge pvalue_T415(in=a) np_T415(in=b);
	by avisn;
	if a;
run;

/*Merging both Paired T test vlaue and non parameter value*/

data fi_pval;
	merge final_T415(in=a) PT_pval(in=b);
	by avisn;
	if a;
run;

/*Assinging Pavlues based on the requiremnts- Less than 0.05 for Wilcoxon and rest are assigned with T test*/

data final_pval;
set fi_pval;
	if nvar="ls" then _Lesional_=npls;
	if nvar="nls" then _Non_Lesional_=npnls;
	if nvar="hs" then _Healthy_=nphs;
	if nvar="lshs" then _Healthy_=nphs;
	if nvar="lshs" then _Lesional_=npls;
	if nvar="nlshs" then _Healthy_Skin_Area=nphs;
	if nvar="nlshs" then _Non_Lesional_=npnls;
	if nvar="lsnls" then _Non_Lesional_=npnls;
	if nvar="lsnls" then _Lesional_=npls;
	if nvar="lsnlshs" then  _Lesional_=npls;
	if nvar="lsnlshs" then _Non_Lesional_=npnls;
	if nvar="lsnlshs" then _Healthy_=nphs;
	;
run;&lt;/PRE&gt;&lt;P&gt;, Is there any way to make it small and create a macro for this&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 09:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883913#M349196</guid>
      <dc:creator>ambadi007</dc:creator>
      <dc:date>2023-07-07T09:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Macro for Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883914#M349197</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I have a requirement to create Pvalue based on distribution of data , below is the requirement. 1 If data follows normal distribution, &lt;STRONG&gt;P-values&lt;/STRONG&gt; were derived using paired sample t-test else by Wilcoxon test for baseline vs all the timepoints. The below codes i have written , but the codes are too lengthy. Could you please help to make it in a macro&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not able to test this, as I don't have your data. But the general idea is to sort and then use a BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=input;
     by parcat1n avisn;
run;

proc ttest data=input alpha=0.05;
    ods output ttests=out;
    by parcat1n avisn;
    paired base*aval;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The general idea here (and hopefully for the rest of your SAS life) is to avoid using macros when a BY statement(s) can do the work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, the same idea applies to using testing the distribution and for non-parametric tests, no need for a macro there either, so I did not write code for that, see if you can follow what I did to get distribution tests and non-parametric tests working without a macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 13:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883914#M349197</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-07T13:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Macro for Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883928#M349203</link>
      <description>As you suggested the first method I have changed and it works...but in second method i need to show baseline VS all other timepoints (i.e visits)</description>
      <pubDate>Fri, 07 Jul 2023 10:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883928#M349203</guid>
      <dc:creator>ambadi007</dc:creator>
      <dc:date>2023-07-07T10:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Macro for Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883930#M349204</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76823"&gt;@ambadi007&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;...but in second method i need to show baseline VS all other timepoints (i.e visits)&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm sorry but I don't know what this brief comment means, I don't know what doesn't work, I don't even know what baseline you are referring to. Please explain in detail.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 10:52:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883930#M349204</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-07T10:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Macro for Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883931#M349205</link>
      <description>need to check the Pvalue for first visit(Baseline) and all other visits</description>
      <pubDate>Fri, 07 Jul 2023 11:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883931#M349205</guid>
      <dc:creator>ambadi007</dc:creator>
      <dc:date>2023-07-07T11:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Macro for Value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883933#M349207</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76823"&gt;@ambadi007&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;need to check the Pvalue for first visit(Baseline) and all other visits&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi, I find this to be unclear as well, and request a detailed explanation. Be generous with information!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 11:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-Macro-for-Value/m-p/883933#M349207</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-07T11:05:21Z</dc:date>
    </item>
  </channel>
</rss>

