Hi,
I need help with making multiple files from my dataset. This is how the dataset looks like:
Community Name Time Values
CommunityA June 56
CommunityB May 94
CommunityC April 54
CommunityD December 10
and so on....
I want to make separate files for each community with thier name identified in the file and rest of the communitites will be blinded.
For eg: Using the dataset above, I want to make 4 different files for each community like this:
For communityA:
Community Name Time Values
CommunityA June 56
2 May 94
3 April 54
4 December 10
The file for communityA will have data for the rest of the communities except the community name is blinded and replaced by 2,3,4.
Similarly the file for CommunityB will look like,
Community Name Time Values
1 June 56
CommunityB May 94
3 April 54
4 December 10
and so on...
Is this possible in SAS? I would greatly appreciate your time and help regarding the same.
Hi,
Try the following code in addition of Proc Format.....
data commA commB commC commD;
set test;
if community_name EQ "communityA" then output commA;
if community_name NE "communityA" then do;
community_name = _N_;
output commA;
end;
if community_name EQ "communityB" then output commB;
if community_name NE "communityB" then do;
community_name = _N_;
if _N_ = '2' then community_name = "communityB";
output commB;
end;
if community_name EQ "communityC" then output commC;
if community_name NE "communityC" then do;
community_name = _N_;
if _N_ = '3' then community_name = "communityC";
output commC;
end;
if community_name EQ "communityD" then output commD;
if community_name NE "communityD" then do;
community_name = _N_;
if _N_ = '4' then community_name = "communityD";
output commD;
end;
run;
If there is many community (say more than 50) then process the same logic with iterative %DO loop within Macro Definition...
Cheers
How about a solution that doesn't involve any new data? You could use custome formats to accomplish the same thing for most analysis.
Proc format library=work;
value $CommunityA
'Community A' = 'Community A'
'Community B' = '1'
'Community C' = '2'
'Community D' = '3'
'Community E' = '4
;
value $CommunityB
'Community A' = '1'
Community B' = 'Community B'
Community C' = '2'
'Community D' = '3'
'Community E' = '4
;
run;
Then for any report procs use the appropriate format. If there are a large number of communities involved it is likely worth making a control data set for proc format.
If you are creating different physical files or datasets, then it is straightforward.
However, if you want the appearance of a common/shared dataset to depend on the reader of the dataset, then just ensure the formatsearch path for the user has the appropriate "blinding" format for that user/usergroup in the first format catalog named in the format search path option (FMTSEARCH)
NuPur20 seems to be requesting files.
If these are SAS datasets, my approach would be different from the "external files" solution.
Hi,
Try the following code in addition of Proc Format.....
data commA commB commC commD;
set test;
if community_name EQ "communityA" then output commA;
if community_name NE "communityA" then do;
community_name = _N_;
output commA;
end;
if community_name EQ "communityB" then output commB;
if community_name NE "communityB" then do;
community_name = _N_;
if _N_ = '2' then community_name = "communityB";
output commB;
end;
if community_name EQ "communityC" then output commC;
if community_name NE "communityC" then do;
community_name = _N_;
if _N_ = '3' then community_name = "communityC";
output commC;
end;
if community_name EQ "communityD" then output commD;
if community_name NE "communityD" then do;
community_name = _N_;
if _N_ = '4' then community_name = "communityD";
output commD;
end;
run;
If there is many community (say more than 50) then process the same logic with iterative %DO loop within Macro Definition...
Cheers
Here is a General Solution, section 3.3:
http://www.sascommunity.org/wiki/Macro_CallText
Ron Fehd macro maven
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.