Desktop productivity for business analysts and programmers

reading from control files the dynamic variables name

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

reading from control files the dynamic variables name

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


Accepted Solutions
Solution
‎08-10-2016 02:50 AM
Super User
Posts: 9,856

Re: reading from control files the dynamic variables name

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


All Replies
Super User
Posts: 19,034

Re: reading from control files the dynamic variables name

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

Super User
Posts: 19,034

Re: reading from control files the dynamic variables name

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

Solution
‎08-10-2016 02:50 AM
Super User
Posts: 9,856

Re: reading from control files the dynamic variables name

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

Contributor
Posts: 23

Re: reading from control files the dynamic variables name

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.

 

Contributor
Posts: 23

Re: Controlling for variable

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

 

Super User
Posts: 19,034

Re: Controlling for variable

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. 

Contributor
Posts: 23

Re: reading from control files the dynamic variables name

hi,

please disregard the last posting, i found the answer.

thank you

 

Super User
Posts: 19,034

Re: reading from control files the dynamic variables name

@SASuserxx Please mark the correct solution please. 

Contributor
Posts: 23

Re: reading from control files the dynamic variables name

@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;

Super User
Posts: 19,034

Re: reading from control files the dynamic variables name

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

Contributor
Posts: 23

Re: reading from control files the dynamic variables name

Hi ,

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

 

thanks

 

Super User
Posts: 9,856

Re: reading from control files the dynamic variables name

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

Contributor
Posts: 23

Re: reading from control files the dynamic variables name

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

Super User
Posts: 19,034

Re: reading from control files the dynamic variables name

[ Edited ]

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. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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