BookmarkSubscribeRSS Feed
mehak
Calcite | Level 5

 

Can anyone tell me how can i write churners and labels in proc sql  .?????
Basically i have two seperate files . one file named as USAGE DATA and the other one named as Churners and labels .

I have imported both the files but dnt know how to write churners and labels in proc sql.

 

*I HAVE IMPORTED BOTH THE FILES LIKE THIS WAY :

libname _class_s "/folders/myfolders/1";

PROC IMPORT DATAFILE="/folders/myfolders/1/SB.csv"

OUT=_class_s.SB

DBMS=CSV

REPLACE;

RUN;

 

 

SAMPLE DATA OF BOTH THE FILES ARE AS

CHURNERS AND LABELS :-

PRODUCT_IDchurn_month
102220594201109
102220594201109
102220594201109
102240104201105
102240104201105
102240104201105
112110440201107

 

USAGE DATA :-

 

 

PRODUCT_IDYearAONCELL_CALL_CNT_M1CELL_CALL_CNT_M2CELL_CALL_CNT_M3CELL_CALL_CNT_M4CELL_CALL_CNT_M5CELL_CALL_CNT_M6
1.02E+0820096000000
1.02E+08201014000000
1.02E+082011115347515177
1.02E+082009100000 

0

 

 

 

 

 

 

9 REPLIES 9
Reeza
Super User

It's not clear at all what you have and what you want. 

 

It would also help if you provide your data as a DATA STEP. There are instructions here on how to set that up:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

mehak
Calcite | Level 5

basically i want to know how to add labels and churners in proc sql

Reeza
Super User

@mehak wrote:

basically i want to know how to add labels and churners in proc sql


What's a churners?

What do you mean by labels?

 

Please remember to post more details with your questions. Showing an example helps.

 

HB
Barite | Level 11 HB
Barite | Level 11

I'm with @Reeza . I have no idea what you want.

 

I can say that anytime data is organized like

 

CELL_CALL_CNT_M1
CELL_CALL_CNT_M2
CELL_CALL_CNT_M3
CELL_CALL_CNT_M4
CELL_CALL_CNT_M5
CELL_CALL_CNT_M6
etc

 

that is a suggestion it may not be normalized and may be difficult to work with.

mehak
Calcite | Level 5

I AM HAVING 3 FILES . i HAVE ATTACHED THE SAMPLE OF ALL THE FILES.

Basically i have to do the following task on this :

import usage data and provide labels from chuners and labels file .

 

I am able to import the data but i dnt know how to provide labels from chuners and labels file

 

 

usage data 

PRODUCT_IDYearAONCELL_CALL_CNT_M1CELL_CALL_CNT_M2CELL_CALL_CNT_M3CELL_CALL_CNT_M4
102107083200960000
1021070832010140000
10210708320111153475151
1021190042009100000
1021190042010130063
10211900420118731133870
102130021200916193203179177
1021300212010211127711
1021300212011201071097988
10213410420091401010
102134104201019127171123123
102134104201117143354338238
10213410520090614355

369

 

 

Churners file 

 

PRODUCT_IDchurn_month
102220594201109
102220594201109
102220594201109
102240104201105
102240104201105
102240104201105
112110440201107
112110440201107
112110440201107
112113214201104
112113214201104
112113214201104
112116660201104
112116660201104

 

 

Labels data file

Variable Label
PRODUCT_IDLine number
YearYear
AONAge on network
CELL_CALL_CNT_M1count of cell calls-April
CELL_CALL_CNT_M2count of cell calls-May
CELL_CALL_CNT_M3count of cell calls-June
CELL_CALL_CNT_M4count of cell calls-July
CELL_CALL_CNT_M5count of cell calls-August 
CELL_CALL_CNT_M6

count of cell calls-September

 

 

 

HB
Barite | Level 11 HB
Barite | Level 11

Is this what you want?

 

data usage_data;
   input product_id $ year aon CELL_CALL_CNT_M1 CELL_CALL_CNT_M2 CELL_CALL_CNT_M3 CELL_CALL_CNT_M4;
datalines;
102107083	2009	6	0	0	0	0
102107083	2010	14	0	0	0	0
102107083	2011	11	53	47	51	51
102119004	2009	10	0	0	0	0
;
run;

data my_usage_data;
	set usage_data;
	label product_id = 'Line number';
	label aon = 'Age on network';
	* etc;
run;

This give us

The SAS System            
             
Line number year Age on CELL_CALL_CNT_M1 CELL_CALL_CNT_M2 CELL_CALL_CNT_M3 CELL_CALL_CNT_M4
network
10210708 2009 6 0 0 0 0
10210708 2010 14 0 0 0 0
10210708 2011 11 53 47 51 51
10211900 2009 10 0 0 0 0

 

???

mehak
Calcite | Level 5

yes sir this is what i want .

But i want  to implement all these things in my original data named as usage data .

HB
Barite | Level 11 HB
Barite | Level 11
>implement all these things in my original data named as usage data

data usage_data;
set usage_data;

will do that. But better to look at @Reeza 's solution.
Reeza
Super User

So, my translation:

 

Q from Mehak:

I have a data set with labels for column names, called Table B.

I have a master data set, called Table A which has the columns. 

I don't know how to apply the labels from Table B to Table A, in a dynamic format, without typing out each label manually. 

 

Here's Table A as a data step:

...

 

Here's Table B as a data step:

...

 

 

 

Answer:

Not sure why the third table matters. And your question didn't initially include the labels, ergo the lack of clarity. 

Here's an example of how that's implemented. If you have issues, post your code and LOG. Good Luck.

 

*Create label data set;
data label_data_set;
length name label $25.;
name="Sex"; label="Gender"; output;
name="height"; label="Height (in)"; output;
name="weight"; label="Weight (lbs)"; output;
run;
 
 
*Create sample dataset to apply label;
data class;
set sashelp.class;
run;
 
 
*Create macro variable that holds label statement;
proc sql noprint;
select catx("=", name, quote(trim(label)))
  into :label_list separated by " "
from label_data_set;
quit;
 
 
*Display macro variable in log;
%put &label_list.;
 
 
*Apply labels without recreating dataset;
proc datasets library=work;
modify class;
label &label_list.;
run;quit;
 
 
*Print the dataset to display new labels;
proc print data=class label noobs;
run;

 

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 9 replies
  • 1757 views
  • 0 likes
  • 3 in conversation