BookmarkSubscribeRSS Feed
Sanchit
Fluorite | Level 6

Hi SAS coders,

 

I'm a new learner of SAS, trying to create a SAS data set from excel file where data is in sheet 1 and Variable Labels are in sheet 2 in the following format:-

 

SHEET1:                                                           SHEET 2

Capture11.PNG      Capture12.PNG

Like this there are 20 columns and their variable labels. Is there a way I can create a data set without manually entering the Variable Labels using Label command? (Using SAS studio)

 

 

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not sure this is a good example for learner to try and do.  What you want is to dynamically create code based on some metadata which is a more advanced topic.  However here is some code, first read in both sheets to datasets:

data _null_;
  set label_dataset end=last;
  if _n_=1 then call execute('data data_dataset; set data_dataset; label');
  call execute(' ',strip(variable),'="',strip(variable_label),'"');
  if last then call execute(';run;');
run;

What the above does is create a datastep with the label <variable>="<variable label>" for each row of your metadata sheet.  So saves you typing it all.  Again though, it is a more advanced topic, and the questions you should be asking is: is excel the best medium for data transfer, and why are column information on a different sheet?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 903 views
  • 1 like
  • 2 in conversation