06-12-2017 05:48 AM - edited 06-12-2017 08:12 AM
I have imported data from excel to a sas-data set. The dataset after exporting looks like this.
Name| ID | Salary | Designation
ABC | 11 | 2000$ | Manager
The table will only have 1 column .
Now I want to validate the column label if an if condition and store the value of column in a macro variable:-
if macro_label="Name" then do; call symput(symget('myMVar'),Name); end;
Please suggest a way to validate the column labels of a sas dataset.
06-12-2017 05:54 AM
You cannot export data from Excel to a SAS dataset; Excel cannot write SAS datasets.
So please describe exactly what you have done to get the data into SAS (which file format was written from Excel, and which step was used in SAS for import)
06-12-2017 06:27 AM
If you have have imported the Excel file into SAS then the metadata will be present in the metadata tables. For instance, if I have a dataset ABC in WORK, then:
data _null_; set sashelp.vcolumns (where=(libname="WORK" and memname="ABC" and name="COL1")); call symputx('myVar',name); run;
Would work. However, why put a column label in a macro variable. It is already present in the metadata tables, so when you want to use it, pull the information from there. Otherwise you may hit several road blocks (invalida characters, line lengths for multiples, multiple values etc.). If you can elaborate on what you are doing we can look.
06-12-2017 08:30 AM
Hello, @Aditi24, I'm really having trouble understanding your problem. Could you give specific examples of what macro variables you want to create from this input data, and what values they should have?
Hello, @RW9, you ask "However, why put a column label in a macro variable." Because that's one legitimate use of macro variables, to contain and make use of text that might vary from one execution of the program to another.
06-12-2017 08:39 AM
Please do stop spamming my posts where I ask simple questions. The reason I asked the question is clearly stated in the text:
"However, why put a column label in a macro variable. It is already present in the metadata tables, so when you want to use it, pull the information from there."
Of which you have only quoted part. In most scenarios it would be quicker and simpler to refer to an existing dataset which contains the required information than to create a whole set of coding to emulate that which is already freely available. If there are specific set of circumstances where this is needed, then other points have to be raised about sepcial characters when de-referencing etc.
06-12-2017 08:57 AM
Ok, RW9, I'll quote the whole thing next time. I still state that putting text into a macro variable for use in a program is a perfectly legitimate thing to do.