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.
ID | Index_n3 | Index_n2.9 | Index_n2.9 | ……… | Index_2.8 | Index_2.9 | Index3.0 |
1 | -3 | -2.9 | -2.8 | ……… | 2.8 | 2.9 | 3 |
2 | -3 | -2.9 | -2.8 | ……… | 2.8 | 2.9 | 3 |
3 | -3 | -2.9 | -2.8 | ……… | 2.8 | 2.9 | 3 |
4 | -3 | -2.9 | -2.8 | ……… | 2.8 | 2.9 | 3 |
5 | -3 | -2.9 | -2.8 | ……… | 2.8 | 2.9 | 3 |
6 | -3 | -2.9 | -2.8 | ……… | 2.8 | 2.9 | 3 |
7 | -3 | -2.9 | -2.8 | ……… | 2.8 | 2.9 | 3 |
8 | -3 | -2.9 | -2.8 | ……… | 2.8 | 2.9 | 3 |
9 | -3 | -2.9 | -2.8 | ……… | 2.8 | 2.9 | 3 |
10 | -3 | -2.9 | -2.8 | ……… | 2.8 | 2.9 | 3 |
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.
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.
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)
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: