turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Designate variable name with intermediate match

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-11-2016 12:17 AM

When specifying variable name,I'm looking for how to designate variables in the middle match for the variable name.

```
data _test;
VAR_A_A=1;
VAR_B_A=2;
VAR_C_A=3;
VAR_A_B=100;
VAR_B_B=200;
VAR_C_B=300;
run;
data _null_;
set _test;
Total_by_colon=sum(of VAR:);put "Total is " Total_by_colon;
run;
```

In this situation, I wanna sum "VAR_A_A" "VAR_B_A" VAR_C_A", which should be ending with answer 6(=1+2+3).

But we know,If we write

sum(of VAR;

This ansiwer is 606(=1+2+3+100+200+300).

From a different point of view, I want to use a regular expression when specifying vars. But it will not be.

I think there is a need to create a macro?

If you have the wisdom, thank you in advance.

Regards,t_ar_taat

Accepted Solutions

Solution

09-11-2016
05:00 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to t_ar_taat

09-11-2016 02:35 AM

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to t_ar_taat

09-11-2016 12:52 AM

You can create a macro or use the VVALUEX logic and obtain the values.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

09-11-2016 04:53 AM

Hi,Reeza

Thank you for giving me your knoledge very quickly.I'll try it.

Solution

09-11-2016
05:00 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to t_ar_taat

09-11-2016 02:35 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ksharp

09-11-2016 04:59 AM

HI,Xia

Thank you very much.

I confirmed your codes work well,in short,answer is actually "6".

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to t_ar_taat

09-12-2016 04:01 AM

Some times picking your variable names may be sufficient. Please look at this:

```
data _test;
VAR_A_A=1;
VAR_A_B=2;
VAR_A_C=3;
VAR_B_A=100;
VAR_B_B=200;
VAR_B_C=300;
Sum1 = sum(of Var_A:);
Sum2 = Sum(of Var_B:);
run;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ballardw

09-13-2016 08:10 AM

Hi,ballardw

Yes,actually the way you showed is also good.

Thank you for your posting.