According to SAS Help Center, vlabel function returns the label that is associated with that variable name, or the variable name if no label exists.
Is it possible to make vlabel return missing value when no label exists?
Parse the result and if the same as the variable then set to missing would be the only approach I am aware of.
However, when you have a label like "Name" for a variable with the name of 'Name' you are going to cause problems.
You can get a missing value for the label by examining sashelp.vcolumn, or dictionary.columns or an output data set created with Proc Contents. If a label is not assigned the Label variable would be missing in the resulting data set.
Example looking at the SAS supplied data set SASHELP.CLASS that you should have installed:
Proc contents data=sashelp.class out=work.classinfo; run;
Or
data work.classinfo2; set sashelp.vcolumn (where=(libname='SASHELP' and memname='CLASS')); run;
Or
proc sql; create table work.classinfo3 as select * from dictionary.columns where libname='SASHELP' and memname='CLASS' ; quit;
Note that the Proc Contents data set has a different structure and content than the the other two.
If using the SASHELP.VCOLUMN or dictionary table the Libname and Memname, library and data set names, must use upper case values from the source as that is how they are stored. The view holding, SASHELP.VCOLUMN holds information of every variable in every data set in your current session and if you don't provide the library and member name you will get a lot of unwanted stuff.
Parse the result and if the same as the variable then set to missing would be the only approach I am aware of.
However, when you have a label like "Name" for a variable with the name of 'Name' you are going to cause problems.
You can get a missing value for the label by examining sashelp.vcolumn, or dictionary.columns or an output data set created with Proc Contents. If a label is not assigned the Label variable would be missing in the resulting data set.
Example looking at the SAS supplied data set SASHELP.CLASS that you should have installed:
Proc contents data=sashelp.class out=work.classinfo; run;
Or
data work.classinfo2; set sashelp.vcolumn (where=(libname='SASHELP' and memname='CLASS')); run;
Or
proc sql; create table work.classinfo3 as select * from dictionary.columns where libname='SASHELP' and memname='CLASS' ; quit;
Note that the Proc Contents data set has a different structure and content than the the other two.
If using the SASHELP.VCOLUMN or dictionary table the Libname and Memname, library and data set names, must use upper case values from the source as that is how they are stored. The view holding, SASHELP.VCOLUMN holds information of every variable in every data set in your current session and if you don't provide the library and member name you will get a lot of unwanted stuff.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.