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
- /
- Macro error: value obtained from proc means in dat...

Topic Options

- 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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-09-2016 12:38 PM

hello,

I am trying to classify a variable (afb_geo) into two group (lower than median vs. higher than median).

I heard sas macro can do this; so, I tried. But there was error.

664 data positive_s;

665 retain RHSP_ID afb_geo ln_afb_geo afb1 age1 date1 afb2 age2 date2 afb3 age3 date3;

666 format hiv_confirm date1-date3 mmddyy10.;

667 set positive_s;

668 call("positive_s", median_afb)=median_afb;

ERROR: Undeclared array referenced: call.

ERROR: Variable call has not been declared as an array.

669 if ln_afb_geo>=median_afb then af_class=2;

670 else af_class=1;

671 run;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.POSITIVE_S may be incomplete. When this step was stopped there were 0

observations and 33 variables.

WARNING: Data set WORK.POSITIVE_S was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.01 seconds

672 data positive_s;

673 retain RHSP_ID afb_geo ln_afb_geo afb1 age1 date1 afb2 age2 date2 afb3 age3 date3;

674 format hiv_confirm date1-date3 mmddyy10.;

675 set positive_s;

676 median_afb=call("positive_s", median_afb);

----

68

ERROR 68-185: The function CALL is unknown, or cannot be accessed.

677 if ln_afb_geo>=median_afb then af_class=2;

678 else af_class=1;

679 run;

NOTE: The SAS System stopped processing this step because of errors.

WARNING: The data set WORK.POSITIVE_S may be incomplete. When this step was stopped there were 0

observations and 33 variables.

WARNING: Data set WORK.POSITIVE_S was not replaced because this step was stopped.

NOTE: DATA statement used (Total process time):

real time 0.02 seconds

cpu time 0.03 seconds

Accepted Solutions

Solution

02-09-2016
01:53 PM

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

Posted in reply to m1ny

02-09-2016 01:30 PM

```
proc means data=positive_s median;
var ln_afb_geo;
output out=median_dataset med(ln_afb_geo)=median;
run;
proc sql noprint;
select median into :median_value
from median_dataset;
quit;
%put &median_value;
data positive_s_cat;
set positive_s_cat;
if ln_afb_geo > &median_value then af_class=2;
else af_class=1;
run;
```

All Replies

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

Posted in reply to m1ny

02-09-2016 12:48 PM

You can do this, but your code is incorrect. CALL isn't a valid function, so I"m not sure what your trying to do there.

Steps in this would be:

1. Calculate median (proc means)

2. Assign to macro variables

3. Use in either SQL or data step to categorize variables.

If you have SAS 9.4 this could be done in one step in proc sql.

Solution

02-09-2016
01:53 PM

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

Posted in reply to m1ny

02-09-2016 01:30 PM

```
proc means data=positive_s median;
var ln_afb_geo;
output out=median_dataset med(ln_afb_geo)=median;
run;
proc sql noprint;
select median into :median_value
from median_dataset;
quit;
%put &median_value;
data positive_s_cat;
set positive_s_cat;
if ln_afb_geo > &median_value then af_class=2;
else af_class=1;
run;
```

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

Posted in reply to Reeza

02-09-2016 01:33 PM

Thank you, Reeza, for your help.

This is my first trial of macro. This is very helpful!