BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Demographer
Pyrite | Level 9

I want to create a synthetic data that is representative of a population by age, sex, region and education. The original table looks like this (see attached for the full file):

agegr

edu

SEX

region

Population

0

e1

0

AD_rural

2180000

0

e1

0

AD_urban

1084307

0

e1

0

AN_rural

9476

0

e1

0

AN_urban

5178

0

e1

0

AR_rural

58663

0

e1

0

AR_urban

13887

...

100

E6

1

WB_rural

23

 

In the synthetic dataset, the weight of each individual should not be higher than 10,000. This means that I should create 218 individuals having the first set of variable (agegr=0, edu=e1, sex=0, AD_rural), each of them having a weight of 10,000.

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Does this do it?

data have;
input agegr edu $ SEX :$1. region :$15. Population;
datalines;
0 e1 0 AD_rural 2180000
0 e1 0 AD_urban 1084307
0 e1 0 AN_rural 9476
0 e1 0 AN_urban 5178
0 e1 0 AR_rural 58663
0 e1 0 AR_urban 13887
;

data want;
set have;
weight = min(10000,population);
gross_weight = weight;
do while (gross_weight < population);
  output;
  weight = min(10000,population - gross_weight);
  gross_weight = gross_weight + weight;
end;
output;
keep agegr edu SEX region weight;
run;

View solution in original post

3 REPLIES 3
Demographer
Pyrite | Level 9
There is none. The weight is now 1 for all line, since it's a population count.
Kurt_Bremser
Super User

Does this do it?

data have;
input agegr edu $ SEX :$1. region :$15. Population;
datalines;
0 e1 0 AD_rural 2180000
0 e1 0 AD_urban 1084307
0 e1 0 AN_rural 9476
0 e1 0 AN_urban 5178
0 e1 0 AR_rural 58663
0 e1 0 AR_urban 13887
;

data want;
set have;
weight = min(10000,population);
gross_weight = weight;
do while (gross_weight < population);
  output;
  weight = min(10000,population - gross_weight);
  gross_weight = gross_weight + weight;
end;
output;
keep agegr edu SEX region weight;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1404 views
  • 0 likes
  • 3 in conversation