DATA Step, Macro, Functions and more

How to generate IDs

Reply
Occasional Contributor
Posts: 8

How to generate IDs

Can you please help me in this.
 
Question:- An Excel file,(Attached with the question) which has a list of villages and the number of auditors required for each block, then you have to create unique IDs for each block. If, for example, there are three villages in a block and six auditors are required, then you need to create 18 unique IDs for the block.
Can you generate unique IDs for each block in a similar fashion? Using SAS or any other tools.
 
please reply asap or before Sunday.
 
Thanks in advance.
Trusted Advisor
Posts: 1,137

Re: How to generate IDs

Posted in reply to pankajdev0027
Your explanation does not match with the villages like for example barsathi , dharampur where the villages are less and auditors are more as per the data provided
Thanks,
Jag
Occasional Contributor
Posts: 8

Re: How to generate IDs

Posted in reply to Jagadishkatam
For Example
Block Name= Barsathi
No. of auditors Required = 7
No. of Villages = 6
No. of IDs required = 42.

So the IDs will be Generate like

Barasathi1_1
Barasathi1_2
Barasathi1_3
Barasathi1_4
Barasathi1_5
Barasathi1_6
Barasathi2_1
Barasathi2_2
Barasathi2_3
Barasathi2_4
Barasathi2_5
Barasathi2_6
.
.
.
.
.
.
.
.
.
Barasathi7_1
Barasathi7_2
Barasathi7_3
Barasathi7_4
Barasathi7_5
Barasathi7_6


So total IDs genertaed 42


Where is the problem Sir.
PROC Star
Posts: 7,468

Re: How to generate IDs

Posted in reply to pankajdev0027

Sounds like the following would do what you want/need:

 

data want (drop=_Smiley Happy;
informat Block_Name $15.;
infile cards dlm='09'x;
input Block_Name No_of_auditors_required No_of_Villages No_of_IDs_required;
do _i=1 to No_of_auditors_required;
do _j=1 to No_of_Villages;
id=catt(Block_Name,_i,'_',_j);
output;
end;
end;
cards;
Badlapur 6 3 18
Barsathi 7 6 42
Bhitargaon 15 30 450
Bilhaur 26 63 1638
Chaubepur 20 45 900
Dharampur 27 66 1782
Dobhi 10 15 150
Ghatampur 15 30 450
Kakwan 17 36 612
Kalyanpur 20 45 900
Karanjakala 80 225 18000
KHUTHAN 8 9 72
Mahrajganj 34 87 2958
Mariahu 18 39 702
Rampur 7 6 42
Shahganj 66 183 12078
Shivrajpur 20 45 900
Sikrara 19 42 798
Sirkoni 30 75 2250
SUITHAKALA 12 21 252
;

 

HTH,

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 8

Re: How to generate IDs

Thank you sir, but
It's not working .
Respected Advisor
Posts: 4,173

Re: How to generate IDs

[ Edited ]
Posted in reply to pankajdev0027

@pankajdev0027

What you want to do must be quite simple to achieve but as @Jagadishkatam points out your narrative of the problem doesn't match with the data you've provided. You need to clarify.

 

If the solution @art297 provided doesn't fit your requirements then just writing "it's not working" is insufficient. You need to explain what's not working as this will help us to understand what you're actually after.

 

Again: Your problem won't be hard to solve. It's all about you explaining us clearly what you have and what you need in order to enable us to provide a working solution.

 

Occasional Contributor
Posts: 8

Re: How to generate IDs

Hi Patrick,

Apologies,
I am uploading the solution in R programming can you convert it in SAS.
Respected Advisor
Posts: 4,173

Re: How to generate IDs

[ Edited ]
Posted in reply to pankajdev0027

I personally don't have R skills but there are quite a few very capable and experienced members in this forum so I'm sure posting existing R code logic will help to illustrate what you're after.

 

Occasional Contributor
Posts: 8

Re: How to generate IDs

Posted in reply to pankajdev0027

Here is the solution but in R programming. So can you please change it to SAS programming.

 

Block <- c("Badlapur","Barsathi","Bhitargaon","Bilhaur","Chaubepur","Dharampur",
"Dobhi","Ghatampur","Kakwan","Kalyanpur","Karanjakala","KHUTHAN",
"Mahrajganj","Mariahu","Rampur","Shahganj","Shivrajpur","Sikrara",
"Sirkoni","SUITHAKALA")

NoA <- c(6,7,15,26,20,27,10,15,17,20,80,8,34,18,7,66,20,19,30,12)

NoV <- c(3,6,30,63,45,66,15,30,36,45,225,9,87,39,6,183,45,42,75,21)


for(m in 1:20){
a <- NoA[m]
b <- NoV[m]


for(j in 1:a){
for(i in 1:b){

print(paste0(Block[m],j,"_",i))
}
}
}



HTH

PROC Star
Posts: 7,468

Re: How to generate IDs

Posted in reply to pankajdev0027

The code I suggested does the same thing as your R code. You never mentioned what form of output you wanted. If you want the same kind of output that you get from your R code, you simply have to add one more proc step, namely:

 

proc print data=want noobs;
var id;
run;

 

Art, CEO, AnalystFinder.com

 

Ask a Question
Discussion stats
  • 9 replies
  • 314 views
  • 1 like
  • 4 in conversation