BookmarkSubscribeRSS Feed
Walternate
Obsidian | Level 7

Hi all,

 

I have a dataset that has:

 

1. Several (hundreds) of variables, any and all of which could theoretically have issues on a given record

2. A summary variable, vars_with_issues, that indicates which variable(s) have issues on a given record

 

icd_var1        icd_var2            icd_var3...icd_var50         vars_with_issues

abc               def                     ghi            jkl                     icd_var1, icd_var3, icd_var50

 

I'm trying to create a test dataset which contains a single column of bad values consisting of the value of each variable indicated above as having a bad value. 

 

bad_values

abc

ghi

jkl

 

So there will be values I do not want in this file (if it's not indicated in vars_with_issues that an issue was found for that var for that record).

 

Here is what I have set up so far. It's not giving me any errors but is not outputting any obs:

 

data test;
     set have (keep = vars_with_issues &list_icd10_vars.);
             array _icd_vars {*} &list_icd10_vars.;
                 do i = 1 to dim(_icd_vars);
                      if vars_with_issues ne ' ' then do;
                             if index(vname(_icd_vars[i]), vars_with_issues) then do;
                                     bad_val = _icd_vars[i];
                                     output;
                             end;
                   end;
           end;
    run;

3 REPLIES 3
ballardw
Super User

I suspect that the data set you want might be easier to make if you did it at the time that you create that hard to use Vars_with_issues.

Perhaps if you share how that variable is made we can point how to create the wanted set at that time.

 

You have the variables in this in the wrong order

      if index(vname(_icd_vars[i]), vars_with_issues) then do;

That says "search the value of the vname to find the entire list of values in vars_with_issues".

Reeza
Super User

Maybe VVALUEX would work instead?

 

data test;
set have;

nWords = countw(vars_with_issues);

do i=1 to nwords;
variableName = scan(vars_with_issues, i, ",");
variableValue = vvaluex(variableName);
output;
end;

keep vars_with_issues variableName variableValue;
run;

@Walternate wrote:

Hi all,

 

I have a dataset that has:

 

1. Several (hundreds) of variables, any and all of which could theoretically have issues on a given record

2. A summary variable, vars_with_issues, that indicates which variable(s) have issues on a given record

 

icd_var1        icd_var2            icd_var3...icd_var50         vars_with_issues

abc               def                     ghi            jkl                     icd_var1, icd_var3, icd_var50

 

I'm trying to create a test dataset which contains a single column of bad values consisting of the value of each variable indicated above as having a bad value. 

 

bad_values

abc

ghi

jkl

 

So there will be values I do not want in this file (if it's not indicated in vars_with_issues that an issue was found for that var for that record).

 

Here is what I have set up so far. It's not giving me any errors but is not outputting any obs:

 

data test;
     set have (keep = vars_with_issues &list_icd10_vars.);
             array _icd_vars {*} &list_icd10_vars.;
                 do i = 1 to dim(_icd_vars);
                      if vars_with_issues ne ' ' then do;
                             if index(vname(_icd_vars[i]), vars_with_issues) then do;
                                     bad_val = _icd_vars[i];
                                     output;
                             end;
                   end;
           end;
    run;


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 634 views
  • 0 likes
  • 4 in conversation