From: Barry Schwarz on
Subtracting 5 from 4 does not yield a positive value. Did you mean
that the access_flag value should be the absolute value of the
difference?

Since your %access% variables are all character and you have their
names in the macro variable &col_name, you can process these variables
in a data step by building an array, something like
array access_variables [*] $ &col_name;

You can also build a macro variable &flag_name similar to &col_name
that contains each variable name with the suffix _flag appended to the
end and then use this macro variable to define another array
array flag_variables [*] &flag_name;

Since you have the same variable names in both data sets, you need to
rename one set. One way would be to build a "rename operand"
containing the old and new name of each %access% variable, something
like
rename = rename || ' ' || extracted_var_name || '=prefix_' ||
extracted_var_name;
where you extract each var_name from &col_name in turn using a loop
and the scan function. When the loop is done, use symput to store the
value in another macro variable &rename_list.

In your data step, you would use this list to rename the variable in
data set one with something like
set one (rename = (&rename_list));

Since you will repeatedly reference the data in access code, I
recommend reading it once and storing the values in two parallel
temporary arrays at the beginning of your data step with something
like
array access_code [access_count] $ 1 _temporary_;
array access_value [access_count] _temporary_;
do i = 1 by 1 until (access_last);
set access_code nobs=access_count end=access_last;
access_char[i] = code;
access_value[i] = value;
end;

You are now ready to do the main processing, something like
set one (rename = (&rename_list));
set two;
do i = 1 to dim(access_variables);
do j = 1 to access_count;
if access_char[j] = access_variables[i] then
do;
value2 = access_value[j];
leave;
end;
if access_char[j] =
vvaluex(vnamex('prefix_' || vname(access_variables[i]))
then
do;
value1 = access_value[j];
leave;
end;
end /*j*/;
flag_name[i] = value2 - value1;
end /*i*/;
output;

On Fri, 16 Apr 2010 07:23:46 -0700 (PDT), Amar Mundankar
<amarmundankar(a)gmail.com> wrote:

>Hi all,
>I have 3 input datasets.
>
>data ONE;
> a_access = 'M';
> Access = 'K';
> z = 2;
> y = 6;
> b_dio_access ='C';
>run;
>data two;
> a_access = 'X';
> b_dio_access = 'A';
> access = 'K';
> z = 62;
> y = 6;
>run;
>data access_code;
> input Code $ Value;
> cards;
>A 1
>C 2
>K 3
>M 4
>X 5
>;
>===========================
>Table Want:
>a_access a_access_flag access access_flag b_dio_access
>b_dio_access_flag y z
>X +1 K
>0 A -1
>6 62
>
>====================================
>I want to compare dataset ONE and TWO based on the column names which
>contains word 'access'.
>So in the comparison only access,a_access,b_dio_access columns will be
>considered.
>The value access,a_access,b_dio_access columns from table TWO will be
>compared with the
>values for respective columns from Table ONE. While comparing the two
>values i have to consider
>values of "Value" column from the Access_Code table.
>e.g. a_access column from table Two has value 'X'and 'M' in table One.
> So I will subtract 5 from 4 (because X=5 and M=4 in access_code
>column).
> Answer is positive so flag value will be +1.
> I will create a column as a_access_flag and will put the value +1 in
>it.
>======================================
>Till now I am only able to find out the column name which contains
>word 'access'.
>And I am able to count the number of columns by writing a macro as
>%wordcnt.
>Plase help me as I need it very urgently.
>
>This is what, I have done so far.
>
>proc sql;
> select distinct(name) into :col_name separated by ' ' from
>dictionary.columns
> where upcase(libname) = 'WORK'
> and upcase(memname) = 'TWO' and upcase(name) like '%ACCESS%';
>quit;
>
>%PUT _USER_;
>%GLOBAL COUNT;
>%macro wordcnt (string);
>
>%let count = 1;
>%do %until (%qscan (&string, &count, %str ( )) = );
>
>%let count = %eval (&count + 1);
>%end;
>%eval (&count - 1)
>
>%mend wordcnt;
>
>%LET X = %WORDCNT(&COL_NAME);
>%PUT &X ;
>========================
>
>Thanks in Advance.
>
>Regards,
>Amar Mundankar.
>

--
Remove del for email