BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASuserxx
Calcite | Level 5

Hi All,

 

i need help on finding a way to read column names from a control table but this control table can be updated by end users by proc import.  any idea is useful for me to experiment. 

 

Below is the dynamic label i need to display to my dataset2. this can be change by users at any time.

examples. 

col1 can be "apples" but then i can change it to "animals"

 

dataset1.

colname dynamic label to display
col1 apples
col2 grapes
col3  banana

 

datset2. 

this dataset ( eg. col1 etc is the one that need to display by the name in the control table above )
       
date col1 col2 col3 
1/07/2016 1 0 1
8/07/2016 0 1 1
15/07/2016 0 0 1



Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

It is easy, as long as you have dataset1.

 

data dataset1;
infile cards expandtabs;
input colname $ label $;
cards;
col1	apples
col2	grapes
col3 	banana
;
run;
 
data datset2; 	 
infile cards expandtabs;	 	 
input date : $20. col1 col2 col3 ;
cards;
1/07/2016	1	0	1
8/07/2016	0	1	1
15/07/2016	0	0	1
;
run;

proc sql noprint;
select cats(colname,'="',label,'"') into : label separated by ' '
 from dataset1;
quit;
proc datasets library=work nolist nodetails;
modify datset2;
label &label ;
quit;

proc print data=datset2 noobs label;run;

x.png

View solution in original post

26 REPLIES 26
Reeza
Super User

Whats your question? Which part of the process do you need help with?

Reeza
Super User

Proc import will read the file from Excel or your source text file. 

Ksharp
Super User

It is easy, as long as you have dataset1.

 

data dataset1;
infile cards expandtabs;
input colname $ label $;
cards;
col1	apples
col2	grapes
col3 	banana
;
run;
 
data datset2; 	 
infile cards expandtabs;	 	 
input date : $20. col1 col2 col3 ;
cards;
1/07/2016	1	0	1
8/07/2016	0	1	1
15/07/2016	0	0	1
;
run;

proc sql noprint;
select cats(colname,'="',label,'"') into : label separated by ' '
 from dataset1;
quit;
proc datasets library=work nolist nodetails;
modify datset2;
label &label ;
quit;

proc print data=datset2 noobs label;run;

x.png

SASuserxx
Calcite | Level 5

Hi ksharp

sorry, ive been away.

 

the code works however im not sure why i get this error.

 

180

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

SASuserxx
Calcite | Level 5

Hi Reeza,

 

thanks for replying.

im not looking to analysis the variables. i just want to rename like a label, except that label is changeable when a user updates the dataset.

 

sorry wasnt clear in my post.

 

thanks

 

Reeza
Super User

As long as run the process from beginning to end each time it's updated its fine. @Ksharp solution is exactly what I would suggest 🙂

 

If you want a trigger to update the dataset when the file is updated that's an order of magnitude difference. 

 

FYI - this seemed to be posted in the wrong thread. I've moved it here. 

SASuserxx
Calcite | Level 5

hi,

please disregard the last posting, i found the answer.

thank you

 

Reeza
Super User

@SASuserxx Please mark the correct solution please. 

SASuserxx
Calcite | Level 5

@Ksharp provided the correct solution

data dataset1;

infile cards expandtabs;

input colname $ label $;

cards;

var1 apple

Var2 banana

Var3 grape

;

run;

 

data datset2;

infile cards expandtabs;

input date : $20. Var1 Var2 Var3 ;

cards;

1/07/2016 1 0 1

8/07/2016 0 1 1

15/07/2016 0 0 1

;

run;

proc sql noprint;

select cats(colname,'="',label,'"') into : label separated by ' '

from dataset1;

quit;

proc datasets library=work nolist nodetails;

modify datset2;

label &label ;

quit;

proc print data=datset2 noobs label;run;

Reeza
Super User

@SASuserxx If you navigate to his post you mark that solution as the answer and the question as solved. 

SASuserxx
Calcite | Level 5

Hi ,

last question, how to do i change to a dataset of the modified data rather than a proc print the result.

 

thanks

 

Ksharp
Super User
The dataset has already been modified.
You can remove PROC PRINT, and use PROC CONTENTS to see what happened.

SASuserxx
Calcite | Level 5

hello,

thanks for replying

i have already tried proc content, however, the modified table will then be used to join to another table to create a new dataset

i just want instead of printing the data ; for it to be a dataset that can be used to create other dataset.

 

thanks

Reeza
Super User

Proc print requires a dataset to print. Isn't that the same dataset you want, ie dataset2 from @Ksharp solution. 

 

The print is only for demonstration purposes. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 26 replies
  • 2680 views
  • 2 likes
  • 3 in conversation