BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jystat
Fluorite | Level 6

Hi,

 

I have a data set that I want to loop based on the column base. 

 

I only have the ID column along with other covariates. Here is the output that I want to have.

 

For example, I want to create the column, names as Index_n3, Index_n2.9, ......, Index_2.9, Index_3.0.

 

The index column is ranged from -3 to 3 by 0.1 or 0.01. For example for the column Index_n3, I want to have -3 in each observation for the whole observation and second column (Index_n2.9  with -2.9 for the whole observations, up to the range 3.0)

 

I kind of know how to create the value in the row basis (with do index = -3 to 3 by 0.01), but not sure for the column basis.

 

I appreciate any help I can get for this problem. Thank you.

 

IDIndex_n3Index_n2.9Index_n2.9………Index_2.8Index_2.9Index3.0
1-3-2.9-2.8………2.82.93
2-3-2.9-2.8………2.82.93
3-3-2.9-2.8………2.82.93
4-3-2.9-2.8………2.82.93
5-3-2.9-2.8………2.82.93
6-3-2.9-2.8………2.82.93
7-3-2.9-2.8………2.82.93
8-3-2.9-2.8………2.82.93
9-3-2.9-2.8………2.82.93
10-3-2.9-2.8………2.82.93
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
If you only need it once, I would suggest a temporary array instead. You can load the values for the array from a data set or dynamically.

View solution in original post

5 REPLIES 5
Reeza
Super User
This is either an array or a data step with a transpose. I'm leaning towards the latter but can you explain a bit what you're trying to do here? There may be an easier way to accomplish what you need.
jystat
Fluorite | Level 6

Hi @Reeza 

 

Thank you for your reply.

 

This index value where the range of -3 to 3 by the step size 0.1 or 0.01, is to find the optimal value in this range. The optimal value is where the value gives the maximum value of Youden index from my new model.

 

Yes, I was searching an array too, but was not clear how to apply for my data. And I was thinking a transpose too, but if I use it, then all of my covariates variables also need to transpose as well. 

Reeza
Super User
If you only need it once, I would suggest a temporary array instead. You can load the values for the array from a data set or dynamically.
ballardw
Super User

SAS variables names typically do not contain . The "." character would separate a library name from a data set name so "index_2.8" would normally reference a library named index_2 (legal) and a data set 8 (illegal), or in some places a datset/variable pair with 8 being an illegal variable name.

 

The headaches involved with setting options to use, and repeatedly typing the acceptable "index_2.8"n construct are often not worth the headaches. If you want a fancy value displayed to indicate what the variable has then assign a label. For many purposes it is MUCH more flexible to have the values, such as 2.8, 2.9, 3.0 stored in another variable. Then much of the code that works will extend when you have values of 3.1, 3.2, 3.3. When you have the values coded into variables then your code has to be rewritten to use additional  variable names (and possibly dropping others). And if the values are all constants as shown the "why" of extra variables becomes very much a question.

Kurt_Bremser
Super User

First of all, you CANNOT have two columns with the exact same name:

Index_n2.9 Index_n2.9

 

Next, to get rid of any ambiguities and be clear, always post your example data in a data step with datalines that we can run to recreate your dataset as is.

By testing that data step, you can pick up any typos you mistakenly made.

It is also STRONGLY recommended to not work with non-valid SAS names by using name literals. That makes coding unnecessarily hard and error-prone.

"If it's stupid and it works, it's still stupid, and you're lucky."

(Maxim 43 of the 70 Maxims of Maximally Effective Mercenaries)

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 599 views
  • 3 likes
  • 4 in conversation