## Doubt in Trim portion in the below code

Occasional Learner
Posts: 1

# Doubt in Trim portion in the below code

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;

Super User
Posts: 10,211

## Re: Doubt in Trim portion in the below code

a) don't write program code in all capitals

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Posts: 79

## Re: Doubt in Trim portion in the below code

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
Super User
Posts: 9,599

## Re: Doubt in Trim portion in the below code

[ Edited ]

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.

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