BookmarkSubscribeRSS Feed
lydia_li
Fluorite | Level 6

Hello, I have a dataset like this:

lydia_li_0-1656523986263.png

I want to update the values in each columns except columns with names containing bins, the value I want to assign is equal to 1, but I want to keep the original column names and re-name the new columns as bin_original column names. So how should I do that with a macro? expect I have 500 columns to modify.

 

Thanks!



22 REPLIES 22
PaigeMiller
Diamond | Level 26

Macros are probably not needed, but an ARRAY might help.

 

However, your description of what you want to do is not clear to me. Please provide a small example with 5 columns and 5 rows showing the data set before any change is applied, and then also showing the data set after any change is applied.

--
Paige Miller
lydia_li
Fluorite | Level 6

This is before:

lydia_li_0-1656524409831.png

and this is after:

lydia_li_2-1656524563654.png

 

no change to the last columns for example, and the name will be updated as Bin_XXX

lydia_li
Fluorite | Level 6
and the original columns still contain in the dataset
PaigeMiller
Diamond | Level 26

Ok, but before I figure out how to do this, what is the reason you want columns where every row has the value of 1? This seems like an odd thing to do. What is the next step of data analysis or reporting that you would do?

--
Paige Miller
lydia_li
Fluorite | Level 6
yes, they only have 1 bin so after I set them to 1, I need to create a macro to calculate WOE and Information values for each of columns variables.
lydia_li
Fluorite | Level 6

This is an example for one variable: 

lydia_li_0-1656525198323.png

But I should apply the function for each of the variables in the dataset

lydia_li
Fluorite | Level 6
I think the format is num as I need the variable to do the calculation
PaigeMiller
Diamond | Level 26

There are weight of evidence macros in SAS that you can find. These don't require columns of 1s. You can also compute weight of evidence in PROC HPBIN, again you don't need columns of 1s.

 

In addition, percent of occurence/non-occurence can be computed via PROC FREQ or PROC MEANS (and probably several other ways) without creating these columns of 1s.


So, I think you should go down one of those paths, rather than create columns of 1s.

--
Paige Miller
lydia_li
Fluorite | Level 6

so would you please show me how to use the following dataset to directly calculate WOE and IV if there is no need to adjust? Thanks! 

lydia_li_0-1656525703917.png

I want each table to have a fromat like this:

lydia_li_1-1656525780229.png

 

lydia_li
Fluorite | Level 6

proc hpbin data=TEMP_INT WOE BINS_META=Mapping;
ods output Mapping=Mapping;
input DelinquentDays/numbin=4;
target DelinquentDays/level=nominal order=desc;
run;

 

 what if I want to apply this HPBIN function to each of the column? What should I do? and what if there is some columns that I dont want to apply? maybe there is a exclusion list and all the columns not in the exclusion list need to go into the loop. is there a macro to do so? Thanks!

PaigeMiller
Diamond | Level 26

The INPUT statement can have as many variables as you want in it.


Also, TARGET must be a different variable than the INPUT variables.

--
Paige Miller
lydia_li
Fluorite | Level 6

thanks, but I still need the solution for changing the value for each column, not just to 1, 1 is an example, so how to do that? Thanks!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 22 replies
  • 2483 views
  • 4 likes
  • 4 in conversation