Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:11:46+00:00 2026-06-14T10:11:46+00:00

In this block of SAS data step code I am setting a Table from

  • 0

In this block of SAS data step code I am setting a Table from an SQL query called TEST_Table. This table contains multiple columns including a larger section of columns titled PREFIX_1 to PREFIX_20. Each column starts with PREFIX_ and then an incrementing number from 1 to 20.

What I would like to do is iteratively cycle through each column and analyze the value of that column.

Below is an example of what I am trying to go for. As you can see I would like to create a variable that increases on each iteration and then I use that count value as a part of the variable name I am checking.

data TEST_Data;
  set TEST_Table;
  retain changing_number;
  
  changing_number=1;
  do while(changing_number<=20);    
    if PREFIX_changing_number='BAD_IDENTIFIER' then do;
      PREFIX_changing_number='This is a bad part';
    end;
  end;  

run;

How would be the best way to do this in SAS? I know I can do it by simply checking each value individually from 1 to 20.

if PREFIX_1 = 'BAD_IDENTIFIER' then do;
  PREFIX_1 = 'This is a bad part';
end;
if PREFIX_2 = ...

But that would be really obnoxious as later I will be doing the same thing with a set of over 40 columns.

Ideas?

SOLUTION

data TEST_Data;
    set TEST_Table;
    
    array SC $ SC1-SC20;
    
    do i=1 to dim(SC);    
      if SC{i}='xxx' then do;
         SC{i}="bad part";
      end;   
    end;  
run;

Thank you for suggesting Arrays 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:11:46+00:00Added an answer on June 14, 2026 at 10:11 am

    You need to look up Array processing in SAS. Simply put, you can do something like this:

    data TEST_Data;
      set TEST_Table;
      *retain changing_number; Remove this - even in your code it does nothing useful;
      array prefixes prefix:; *one of a number of ways to do this;
      changing_number=1;
      do while(changing_number<=20);    
        if prefixes[changing_number]='BAD_IDENTIFIER' then do;
           prefixes[changing_number]='This is a bad part';
        end;
      end;  
    
    run;
    

    A slightly better loop is:

    do changing_number = 1 to dim(prefixes);
    ... loop ...
    end;
    

    As that’s all in one step, and it is flexible with the number of array elements (dim = number of elements in the array).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For this block of code: if(!skipit) { var update_argument=''; if (document.formname.fieldname) { update_argument=document.formname.fieldname[document.formname.fieldname.selectedIndex].value; }
I have this block of code inside a loop: var points = [new google.maps.LatLng(lat1,
i have seen this block of code in this Stackoverflow as a answer of
I have this block of xaml and I made a ViewModel which contains a
I have this block of code where when I hover (click for purposes of
I am using this block of code to mimic the way files are uploaded:
There is a problem executing this block of code while passing the parameter. Parameter
I seem to be using this block of code alot in Python. if Y
My data structure is a linked list of blocks. A block contains 31 elements
It looks like this block directly flushes the output. What's the practical use of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.