Help using Base SAS procedures

Count = count+1 equivalent for String Operations

Accepted Solution Solved
Reply
Contributor ykk
Contributor
Posts: 24
Accepted Solution

Count = count+1 equivalent for String Operations

I had written  the below code

msr='TEST';

            count =1;

            if COALESCE(NEW_GLOBAL_MIN,EXISTING_GLOBAL_MIN) eq . then

                do;

                    msr = msr||'GLOBAL_MIN';

                    count = count+1;

                    put msr;

                    put 'inside 1 if';    

                end;

            if COALESCE(NEW_GLOBAL_MEDIAN,EXISTING_GLOBAL_MEDIAN) = . then

                do;

                    msr = msr||',GLOBAL_MEDIAN';

                    PUT msr;

                    count = count+1;

                end;

            if COALESCE(NEW_GLOBAL_MAX,EXISTING_GLOBAL_MAX) = . then

                do;

                    msr = msr||',GLOBAL_MAX';

                    PUT msr;

                    count = count+1;

                end;

            if COALESCE(NEW_LOCAL_MIN,EXISTING_LOCAL_MIN) = . then

                do;

                    msr = msr||'LOCAL_MIN';

                    PUT msr;

                    count = count+1;

                end;

            if COALESCE(NEW_LOCAL_MEDIAN,EXISTING_LOCAL_MEDIAN) = . then

                do;

                    msr = msr||',LOCAL_MEDIAN';

                    PUT msr;

                    count = count+1;

                end;

            if COALESCE(NEW_LOCAL_MAX,EXISTING_LOCAL_MAX) = . then

                do;

                    msr = msr||',LOCAL_MAX';

                    PUT msr;

                    count = count+1;

                end;

put msr;

put count;

Once this is executed in the end I am expecting values 'TEST GLOBAL MIN GLOBAL MEDIAN ...'etc but I can see only TEST in the log when I print the variable msr at the end.But the value of count is 7 which confirms that all the code in the 6 if statements is executed.

Can you please help me in fixing the above issue.

Thanks

Kiran


Accepted Solutions
Solution
‎12-15-2014 04:57 PM
Contributor ykk
Contributor
Posts: 24

Re: Count = count+1 equivalent for String Operations

I had updated the code to use trim() while concatenating the 2 variables.I am getting the output correctly now.

View solution in original post


All Replies
Super User
Posts: 19,815

Re: Count = count+1 equivalent for String Operations

change the length of the Test variable at the top of your code:

length mar $20.;

msr='TEST';


.... remaining sas code

Solution
‎12-15-2014 04:57 PM
Contributor ykk
Contributor
Posts: 24

Re: Count = count+1 equivalent for String Operations

I had updated the code to use trim() while concatenating the 2 variables.I am getting the output correctly now.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 266 views
  • 3 likes
  • 2 in conversation