- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 10-01-2010 11:39 AM
(2339 views)
here is what I want to do:
I have a list of numbers stored in a macro variable, I want to find out if this list of numbers in the macro variables are all the ids or a subset of ids in a dataset.
I saw there is a vinarray function in sas help but the example is not well documented, I do not understand how it would work.
of course, I could use scan to get a id at a time and then to look it up in the dataset but I think there got be a easier way.
any suggestion? thank you very much in advance.
I have a list of numbers stored in a macro variable, I want to find out if this list of numbers in the macro variables are all the ids or a subset of ids in a dataset.
I saw there is a vinarray function in sas help but the example is not well documented, I do not understand how it would work.
of course, I could use scan to get a id at a time and then to look it up in the dataset but I think there got be a easier way.
any suggestion? thank you very much in advance.
12 REPLIES 12
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
can you send an example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
For me, it's unclear if you are concerned about SAS variables or SAS variable "values"? I see a reasonable example in the SAS 9.2 DOC on VINARRAY function - here:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000245979.htm
Scott Barry
SBBWorks, Inc.
Suggested Google advanced search argument, this topic / post:
vinarray site:sas.com
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a000245979.htm
Scott Barry
SBBWorks, Inc.
Suggested Google advanced search argument, this topic / post:
vinarray site:sas.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you for the example. then vinarray would not meet my need since it checks if the variable is in the arrray. I want to check if the value is in the array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You will need to parse each sub-field in "B" and check for its value in "A", or the opposite, as you require. The process can done with either SAS macro language using %SCAN and %SYSFUNC(INDEX(argument1,argument2)) or with a DATA step, using the similar CALL function SCAN and INDEX(argument1,argument2).
Scott Barry
SBBWorks, Inc.
Scott Barry
SBBWorks, Inc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
index would not work since
index("1 23 3", "2") will return 3, which is not what I want.
index("1 23 3", "2") will return 3, which is not what I want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I guess I can trick it by doing
index ("1 23 3", "2 ");
but I really wish there is some sas function out there which can look for a number rather than just chars.
index ("1 23 3", "2 ");
but I really wish there is some sas function out there which can look for a number rather than just chars.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can treat them as WORDS using INDEXW.
Or you can use WHICHN function as in this example.
[pre]
1612 %let id_list1=%str(1 23 2 3);
1613 %let id_list2=%str(1 2 3 4);
1614
1615 data _null_;
1616 array _a[%sysfunc(countw(&id_list1))] (&id_list1);
1617 array _b[%sysfunc(countw(&id_list2))] (&id_list2);
1618 do i = 1 to dim(_a);
1619 f = whichN(_a,of _b);
1620 if f eq 0 then put 'NOTE: The value ' _a 'from id_list1 is not in id_list2.';
1621 end;
1622 run;
NOTE: The value 23 from id_list1 is not in id_list2.
[/pre] Message was edited by: data _null_;
Or you can use WHICHN function as in this example.
[pre]
1612 %let id_list1=%str(1 23 2 3);
1613 %let id_list2=%str(1 2 3 4);
1614
1615 data _null_;
1616 array _a[%sysfunc(countw(&id_list1))] (&id_list1);
1617 array _b[%sysfunc(countw(&id_list2))] (&id_list2);
1618 do i = 1 to dim(_a);
1619 f = whichN(_a,of _b
1620 if f eq 0 then put 'NOTE: The value ' _a 'from id_list1 is not in id_list2.';
1621 end;
1622 run;
NOTE: The value 23 from id_list1 is not in id_list2.
[/pre] Message was edited by: data _null_;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
perfect, that is what I want exactly.
thank you so much, 🙂
have a good weekend.
thank you so much, 🙂
have a good weekend.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
one more question, is there way to break the do loop when I see a unmatch, since once a unmatch found, there is no need to do the rest check any more.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
LEAVE;
[pre]
%let id_list1=%str(1 23 2 3);
%let id_list2=%str(1 2 3 4);
data _null_;
array _a[%sysfunc(countw(&id_list1))] (&id_list1);
array _b[%sysfunc(countw(&id_list2))] (&id_list2);
do k = 1 to dim(_a);
f = whichN(_a,of _b);
if f eq 0 then do;
put 'NOTE: The value ' _a 'from id_list1 is not in id_list2.';
leave;
end;
end;
put 'NOTE: stopped at ' K=;
run;
[/pre]
[pre]
%let id_list1=%str(1 23 2 3);
%let id_list2=%str(1 2 3 4);
data _null_;
array _a[%sysfunc(countw(&id_list1))] (&id_list1);
array _b[%sysfunc(countw(&id_list2))] (&id_list2);
do k = 1 to dim(_a);
f = whichN(_a
if f eq 0 then do;
put 'NOTE: The value ' _a
leave;
end;
end;
put 'NOTE: stopped at ' K=;
run;
[/pre]
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
thank you, data _null_.
I see correct the sample code, _a even, 🙂
I see correct the sample code, _a
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
for example,
%let id_list1=%str(1 23 2 3);
%let id_list2=%(str(1 2 3 4);
I wonder if there is an efficient way to determine that 23 is not in id_list2 .
%let id_list1=%str(1 23 2 3);
%let id_list2=%(str(1 2 3 4);
I wonder if there is an efficient way to determine that 23 is not in id_list2 .