BookmarkSubscribeRSS Feed
pankajdev0027
Fluorite | Level 6
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.
9 REPLIES 9
Jagadishkatam
Amethyst | Level 16
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
pankajdev0027
Fluorite | Level 6
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.
art297
Opal | Level 21

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

 

data want (drop=_:);
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

 

pankajdev0027
Fluorite | Level 6
Thank you sir, but
It's not working .
Patrick
Opal | Level 21

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

 

pankajdev0027
Fluorite | Level 6
Hi Patrick,

Apologies,
I am uploading the solution in R programming can you convert it in SAS.
Patrick
Opal | Level 21

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.

 

pankajdev0027
Fluorite | Level 6

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

art297
Opal | Level 21

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

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1349 views
  • 1 like
  • 4 in conversation