BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a variable whose values are a comma delimited text string:

Var1
3,5
4,7,9,11
15,17,19,21,23

Each value in the text string represents an associated beta value in another sas data set. So 3,5 represents B3 & B5 found in dataset PARMS. I need a method of

a) parsing through the values in the string (I chose an array)
b) then associating those values with the beta values in another dataset
(I was thinking an array of macro variables)

The structure of the beta data set includes a beta variable for every B(i), e.g. B1=value B2=value. It is a single row of data. There are currently a few additional columns that include _TYPE_, etc.

Since I want to refer to the value of each B(i) I thought an array of macro variables would do the trick. I could use some assistance and suggestions w.r.t creating the array of string values....but am more in need of assistance w.r.t. referencing actual values of B(i), how and when do I call them.

Am I doing something in multiple steps that can be accomplished going directly from list to beta value....I think the macro array is necessary but would like confirmation.
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
A DATA step approach to parse out the input, creating some max number of B1 through Bnn SAS variables (not macro). Suggest calling these variable some different prefix, so that you can correlate them back to the Bnn variables in your beta dataset. Parsing can use DO UNTIL( = ' '); END; or some DO / END technique, keeping track of the max suffix value thus far (as a RETAIN variable since you have multiple input records).

Sounds like a straightforward SAS (non macro language) task to me, however you might benefit from a macro variable to set the maximum SAS Bnn or new_Bnn var suffix (the "nn" portion).


Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Something like this maybe.... but I don't see how to accomplish the sequential variable names without a macro, the number will vary by group so I don't want to explicitly list them. What am I missing?


data altbs;
set altbs;
by ists tosts;
do i=1 to 5;
do until (last.ists);
do until (last.tsts);
do while n < maxcnt;
**this is where I'm stuck where abeta(n) is abeta1 - abeta(maxcnt -1);
abetan=scan(altb,n,',');
end;
end;
end;
end;
run;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
One step at a time -- pre-parse your incoming data and set a max var suffix using CALL SYMPUT. You're going to have to take it from this point.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
This is my incoming data

Var1
obs 3,5
obs 4,7,9,11
obs 15,17,19,21,23

Can anyone provide some more details. I don't know what to do with the suggestion.
deleted_user
Not applicable
I'm going to rephrase my question it's more of a conceptual question.

I have a variable whose value is a comma delimited text string. The text string itself it is a series of values. The number of values in the text string varies from record to record. The number of values in each text string is identified by another variable mxcnt, (mxcnt -1) has been defined as the the number of values in the text string.

Ultimately I will want to use these values 3,5,7 to refer to a variable in another table(single vector of b1 variables and their relative values)namely b3,b5,b7 and return the value of the respective b variable.

What is the best approach, if in the long run I'm using the values to reference variables in another table.
Peter_C
Rhodochrosite | Level 12
design
you have run-time information in a variable (in I presume, more than one row) of a data-set. So, why try to solve the lookup with compile-time information like macro variables?
The classic solutions would be either an indexed set statement, or an informat lookup (well, you have a string and want the corresponding numeric value from another table).
Since SAS9 the new alternative to consider is a hash table lookup. Over formats and informats, hash tables have the advantage of indexing on multiple keys and can return more than one value, and all these keys and data can be of mixed data-types.
Each of these alternative techniques will feature among the Samples you'll find searchable in the http://support.sas.com site.
Good luck as you discover the wealth of ideas provided there.

PeterC
ChrisNZ
Tourmaline | Level 20
Also useful: function VVALUEX allows you to look up another variable's value whose name you derive on the fly.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 3923 views
  • 0 likes
  • 4 in conversation