BookmarkSubscribeRSS Feed
GokulakrishnanSethuraman
Calcite | Level 5

     ARRAY SCD(*)   SC001-SC500;

      DO IS = 1 TO 500;

          IF SUBSTR(SCD(IS),1,1) > "V" THEN I = 500;

          ELSE

          IF SUBSTR(SCD(IS),1,1) = '*' THEN

            DO;

             SUBSTR(TRIM,1,2) = SUBSTR(SCD(IS),2,2);

             TRIM1 = SUBSTR(SCD(IS),1,3);

            END;

          ELSE

          IF SUBSTR(SCD(IS),1,1) = '-' THEN

            DO;

             SUBSTR(TRIM,3,2) = SUBSTR(SCD(IS),2,2);

             TRIM2 = SUBSTR(SCD(IS),1,3);

            END;

3 REPLIES 3
mnjtrana
Pyrite | Level 9

do you have doubt in below statement:

SUBSTR(TRIM,1,2) = SUBSTR(SCD(IS),2,2);

 

If yes, here, TRIM is a variable and you are replacing its first 2 bytes from he SCD array


Cheers from India!

Manjeet
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What is the question here?  Post eaxmple test data, in the form of a datastep, and what you expect the output to be so that we can see what the process is.  Avoid coding in capitals as this makes code very hard to read.  Use the code blocks - it is a {I} above where you post, which moves code to a proper editor area.  It looks to me like you could simplfy your if branching down to one select:

do is=1 to 500;
  select;
    when (substr(scd(is),1,1) > "V") i=500;
    when ...;
  end;
end;

Do note, I would advise not doing the substr(scd(is),1,1) > "V", that isn't what I would call logical approach.  V is a character, it works as it also has an associated ASCII code, which is what you are comparing there, but that doesn't mean that "x" would be > "V" for instance.  I would say, 

upcase(substr(scd(is),1,1)) in ("W","X","Y","Z")

would be a clearer way of writing it.

 

Edit:  One other thing to add.  It always jumps out at me when someone states they have > 50 variables in a dataset.  My first question would always be why?  There are some instances of course where it is easier, and sometimes necessary to do it this way, however I find that most times many variables makes hard work.  It may be that your logic can be simplified merely by restructuring your data into a normalised form.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 682 views
  • 2 likes
  • 4 in conversation