BookmarkSubscribeRSS Feed
Ronin
Obsidian | Level 7

Hi all, 

Its my second day in life with SAS and I am struggling but learning a lot with this community's help. I am facing a situation here at work and hope will get some suitable solutions for you guys.

 

I had two datasets:

dataset 1 (with 86 variable and 7095 observation)- 

Var 1var 2WEEKvar 4STOREvar 6var 7…….var 86
af101x……………………
bk6053x……………………
cz6602x……………………
dx50053x……………………
ey308x……………………
………….………….………….………….………….………….……………………
………….………….………….………….………….………….……………………

this will continue for all 7095 observations....

 

and dataset 2 (2 variables and 621 unique observations)

 

STORETIER
1Tier A
2Tier C
3Tier B
8Tier B
9Tier C
53Tier A
18Tier C
98Tier B

continued till 621 rows with 621 unique Store values....

 

I had modified the dataset 1 with by adding a numerically encoded new_variable with logic based on WEEK variable from dataset 1 and Tier column from dataset 2 and the output should come like:

 

Var 1Var 2WEEKVar 4STOREVar 6Var 7var 8…………….var 85var 86new_variable
af101xy……………………………..7 j11
bk6053xy……………………………..j u 611
cz6602xy……………………………..next 723
dx50053xy……………………………..j e s t k #211
ey308xy……………………………..l k j l_8712
fj5109xy……………………………..j k j_76923
gm4908xy……………………………..78_65_k j u12

 

 But unfortunately I am getting the new SAS dataset as:

 

 Var 1Var 2WEEKVar 4STOREVar 6Var 7var 8…………….var 85var 86new_variable
 af101xy……………………………..7 j 
11          
 bk6053xy……………………………..j u 6 
11          
 cz6602xy……………………………..next 7 
23          
 dx50053xy……………………………..j e s t k #2 
11          
 ey308xy……………………………..l k j l_87 
12          
 fj5109xy……………………………..j k j_769 
23          
 gm4908xy……………………………..78_65_k j u
12          

 

also when I converted the SAS file to CSV (.sas7bdat to .csv) then the output looks like:

 

Var 1Var 2WEEKVar 4STOREVar 6Var 7var 8…………….var 85var 86new_variable
af101xy……………………………..7 j 
 11        
bk6053xy……………………………..j u 6 
 11        
cz6602xy……………………………..next 7 
 23        
dx50053xy……………………………..j e s t k #2 
 11        
ey308xy……………………………..l k j l_87 
 12        
fj5109xy……………………………..j k j_769 
 23        
gm4908xy……………………………..78_65_k j u 
 12        

 

 I also got a warning message in log file which says:

 

WARNING: Multiple lengths were specified for the BY variable STORE by input data sets. This may cause unexpected results.

 

Can it be because of this. I am unable to solve it . Please help..

 

2 REPLIES 2
gamotte
Rhodochrosite | Level 12
Hello,
Can you post the complete log for an execution of your program ?
Ronin
Obsidian | Level 7

hi sorry for delay was stuck with other project.

PFA the log file for one execution. Moreover I want to clarify something in actual data in place of Tier A, Tier B and Tier C its Tier 1, Tier 2 and Control and the threshold week 50 is coded as week=1968.

 

I have edited the distorted CSV file after the code execution...I found a issue that as per the code which you have given:

 

below logicis working well:

if WEEK le 50 then newvar=10;
    else newvar=20;

 But, for all observations in the next logic:

if upcase(TIER)="TIER A" then newvar=newvar+1;
    else if  upcase(TIER)="TIER B" then newvar=newvar+2;
    else newvar=newvar+3;

 the commad is directly moving to else statement resulting all the values of new variable as either 13 or 23 even for the place where it should be 11, 12, 21, 22

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2 replies
  • 1814 views
  • 0 likes
  • 2 in conversation