Hi,
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:-
pseudo code:-
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.
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)
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.
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.
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.